the wiki touches on this
When overriding awakeFromInsertion(...) there are two times that this method
can be called when the EO being inserted is not actually being initialized for
the first time.
If it's being reinserted to a EC after it was deleted from another or the same
EC. Only new EOs will have a temporary GlobalID.
If it's being saved to the server-side application by a Java Client WebObjects
application. These EOs will have been inserted on the client-side and likely
already have values set. To avoid overriding these values, you should verify
that the attribute's value is null first.
and it gives a code example of checking if the globalIDForObject isTemporary
so it seems to me that the answer is to use awakeFromInsertion, but do the
check to be sure that the global id is NOT temporary or rather, in my case put
my relationship creation code in a block that first checks if the global id is
temporary as I only want this to run when I create a new EO.
@Override
public void awakeFromInsertion(EOEditingContext ec) {
super.awakeFromInsertion(ec);
EOGlobalID gid = ec.globalIDForObject(this);
if(gid.isTemporary()) {
for (Person aPerson: Person.fetchPersons(ec,
Person.IS_PRIMARY.eq(true).and(Person.CURRENT.eq(true)), null)) {
ShowPerson.createShowPerson(ec, aPerson, this);
}
}
}
Thanks for sharing Ken and John!!
On Jun 6, 2014, at 10:22 AM, Ken Anderson <[email protected]> wrote:
> Well OK then! Someone should up the commandments. Thanks John.
>
> On Jun 6, 2014, at 10:21 AM, John Huss <[email protected]> wrote:
>
>> Except awakeFromInsertion is buggy and replaced by init in Wonder:
>>
>> /**
>> * used for initialization stuff instead of awakeFromInsertion.
>> * <code>awakeFromInsertions</code> is buggy because if an EO is deleted
>> * and then its EOEditingContext is reverted using 'revert' for example then
>> * EOF will -insert- this EO again in its EOEditingContext which in turn
>> * calls awakeFromInsertion again.
>> * /
>> protected void init(EOEditingContext ec)
>>
>>
>>
>> On Fri, Jun 6, 2014 at 9:18 AM, Ken Anderson <[email protected]> wrote:
>> Please read the relevant commandment - :)
>>
>> http://wiki.wocommunity.org/display/documentation/EOF-Using+EOF-The+EOF+Commandments
>>
>> Ken
>>
>> On Jun 6, 2014, at 10:17 AM, Theodore Petrosky <[email protected]> wrote:
>>
>>> Why did you choose this method to override?
>>>
>>> Why do you not use the init method? Does the awake method happen later in
>>> the creation of the Entity?
>>>
>>> Ted
>>>
>>>
>>> On Jun 6, 2014, at 10:05 AM, Ken Anderson <[email protected]> wrote:
>>>
>>>> Ted,
>>>>
>>>> I put this type of stuff in:
>>>>
>>>> public void awakeFromInsertion(EOEditingContext ec) {
>>>> super.awakeFromInsertion(ec);
>>>>
>>>> // my code
>>>> }
>>>>
>>>> Ken
>>>>
>>>> On Jun 6, 2014, at 9:51 AM, Theodore Petrosky <[email protected]> wrote:
>>>>
>>>>> I am starting a project. a booking app for a theater. basically I want to
>>>>> assign all my primary players to a show date when I create a new show
>>>>> date (event).
>>>>>
>>>>> I could have 50 musicians, but only 10 are the primary players. my Person
>>>>> entity has a boolean 'isPrimary' to indicate that this person is a
>>>>> primary player.
>>>>>
>>>>> Entity ShowDate has a to many relationship to showPerson
>>>>> Entity Person has a to many relationship to showPerson
>>>>>
>>>>> In my init method of ShowDate I added:
>>>>>
>>>>> public void init(EOEditingContext ec) {
>>>>> super.init(ec);
>>>>>
>>>>> for (Person aPerson: Person.fetchPersons(ec,
>>>>> Person.IS_PRIMARY.eq(true).and(Person.CURRENT.eq(true)), null)) {
>>>>> ShowPerson.createShowPerson(ec, aPerson, this);
>>>>> }
>>>>> }
>>>>>
>>>>> This is working beautifully. When I create a new ShowDate, I get all the
>>>>> primary musicians added to the date.
>>>>>
>>>>> am I stepping on myself? Since the init method is only called when we
>>>>> create a new instance of an entity, this can only get called once, yes?
>>>>> There isn't a betterer (that's real good english) way? Or a more WO
>>>>> prescribed way?
>>>>>
>>>>> I am making this up as I go and when I stumble across a method that
>>>>> works, I question when it is so easy.
>>>>>
>>>>> Ted
>>>>> _______________________________________________
>>>>> Do not post admin requests to the list. They will be ignored.
>>>>> Webobjects-dev mailing list ([email protected])
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>> https://lists.apple.com/mailman/options/webobjects-dev/kenlists%40anderhome.com
>>>>>
>>>>> This email sent to [email protected]
>>>>
>>>
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list ([email protected])
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/johnthuss%40gmail.com
>>
>> This email sent to [email protected]
>>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]