• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Setting an attribute based on PK?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting an attribute based on PK?


  • Subject: Setting an attribute based on PK?
  • From: Ashley Aitken <email@hidden>
  • Date: Sun, 25 Apr 2004 16:16:55 +0800

Howdy All,

I want to set an attribute (not the primary key) based on the primaryKey value. But, of course, the primary key is not generated until during the initial saveChanges.

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.

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.

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 _______________________________________________ webobjects-dev mailing list | email@hidden Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Setting an attribute based on PK?
      • From: Chuck Hill <email@hidden>
    • Re: Setting an attribute based on PK?
      • From: "Glenn L. Austin" <email@hidden>
    • Re: Setting an attribute based on PK?
      • From: Ashley Aitken <email@hidden>
  • Prev by Date: Re: WOB and class static variables
  • Next by Date: Pre Built Image Management Projects
  • Previous by thread: Re: WOB and class static variables
  • Next by thread: Re: Setting an attribute based on PK?
  • Index(es):
    • Date
    • Thread