Re: Setting an attribute based on PK?
Chuck Hill <[email protected]> Sun, 25 Apr 2004 10:38:50 -0700
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
If all you need is an unique value, then why torture EOF? Some possibilities: - create a session and grab the session ID. Quick, dirty, effective. - use one of the digest algorithms to digest information on the object and produce a unique value - use EO_PK_TABLE or the database's PK generation support to generate a number just for this purpose. - use and EO to keep track of the last used value, use this value +1 and update it on an insert of the other object More below. At 04:16 PM 25/04/2004 +0800, Ashley Aitken wrote: > >Howdy All, > >I want to set an attribute (not the primary key) based on the >primaryKey value. > No. You want to set an attribute (not the primary key) to a unique value. You've just fixated on the primary key value. :-) >But, of course, the primary key is not generated >until during the initial saveChanges. > Actually not until quite late in the game. >Here's what I tried to do: > >Briefly, I added a custom primary key generation delegate that calls >the standard primary key generation method but then also calls a method >to set the other attribute. > >All this seems to work fine - well all the code gets called - I see the >primary key being generated on save, I see the original value of the >other attribute as expected, I see the updated value as expected. > Yeah.... >The only thing is, it still saves the original value of the other >attribute. I seem to remember it is ill-advised to change an EO during >validation (although this is not validation, probably later) maybe this >is similar. > You're changing things that EOF considers already settled. This is way, way too late to be mucking about changing attibute values. Chuck >My thinking is that the operations would happen in this order: >saveChanges > validation (I have none) > primaryKey generation + changing other attribute (using >takeStoredValueForKey) > generating and executing SQL to save new row > >But, as I mentioned, I can't seem to make my changes to the other >attribute get used in the actual save (the changes occur - I can see >them with storedValueForKey - but are not written to the database). > >Any ideas? If not what is wrong with this, how better to do what I am >trying to do. > >Thanks in advance, >Ashley. > >PS Why do I want to do this? > >The entity has an entityCode (not the primary key) but used by the user >to refer to items (so it should be unique, but not strictly so). I >give the user an opportunity to set this entityCode (in fact, I require >it) but if they set it to "*" then it should be auto-generated. To do >that, I am, at present, just trying to give it the value of the primary >key (an integer to string), but later I may want to combine it will >some other attributes to make a more meaningful entityCode (eg WOT-12). > > >-- >Ashley Aitken >Perth, Western Australia >mrhatken at mac dot com > >_______________________________________________ >EOF mailing list >[email protected] >http://www.omnigroup.com/mailman/listinfo/eof > -- Chuck Hill [email protected] Global Village Consulting Inc. http://www.global-village.net