Re: assigning relationship in willInsert()
Re: assigning relationship in willInsert()
- Subject: Re: assigning relationship in willInsert()
- From: Theodore Petrosky <email@hidden>
- Date: Thu, 12 Feb 2015 15:38:23 -0500
On Feb 12, 2015, at 12:15 PM, Ramsey Gurley <email@hidden> wrote:
>
> On Feb 11, 2015, at 10:46 PM, Theodore Petrosky <email@hidden> wrote:
>
>> But there are rules about these books. There are 15 persons assigned to the Reed1 book for Show01. Only one of them is the PrimaryPlayer. Likewise there are 20 other books assigned to this Show.
>
> How do you know who is the primary if you have 15 people assigned to the book? Enforce that in the model.
it is enforced in the model!
No Person is assigned to a Book, I have a PersonBook Entity and a Person is assigned to a PersonBook (Book, Person, isPrimaryPlayer)
so in the above, I have 15 people assigned to a PersonBook where the Book is Reed1 and the PersonBook.book.show is Show01. Only one of these PersonBooks is marked "isPrimaryPlayer = true"
Person toMany personBooks
PersonBook toOne Person and toOne Book with a boolean isPrimaryPlayer
>
> Event
> ->>eventBooks
> ->primaryEventBook
>
> Now an event can only have one primary. Note, this creates a circular relationship. Your database has to be able to do deferred constraints. Pick a good one.
>
> Notice that now you have created this relationship, your problem is solved. You can have a wizard interface
>
> ([tab1], show, date, [tab2], eventBooks, [tab3], primaryEventBook)
>
> You select a show and date. When you go to the next page, you can auto populate your event books relationship with persons based on PersonShow. When you go to the next page, you can have the user select one of your existing EventBooks filtered by isPrimaryPlayer from PersonBook. If there’s only one, then it is automatically assigned. If there are none, then you auto populate a new event book with a null person.
I don’t understand how to accomplish what you said. I go to tab2 (eventBooks). How do I auto populate the eventBooks with primaryPlayers. Keep in mind that the User that is creating the Events, doesn’t know nor care about who is the auto populated people. Each Primary player has to log in and manage who is playing ‘their’ book at a given Event. So you are correct, if when auto populating the books to an event, there is no one assigned as the primary player, so what. the book is assigned and the player is null.
Ideally, in your example above, on Tab1 I select the show and the date. Go to tab2 and all the appropriate EventBooks for this show are applied.
I don’t see the need for tab2!
which brings me full circle to ask where (at what point in the process) to add these related EOs. It seems from the documentation that willInsert() happens very late. according to the docs:
/**
* Called as part of the augmented transaction process.
* This method is called after saveChanges is called on
* the editing context, but before the object is actually
* inserted into the database. This method is also called
* before <code>validateForInsert</code> is called on this
* object. This method is called by the editing context
* delegate {@link ERXDefaultEditingContextDelegate}.
*/
public abstract void willInsert();
so willInsert means willInsertIntoDatabase
wow, AFTER saveChanges but before the object is actually inserted into the database. so what happens if there is an error (I don’t know what). does an empty event get saved, or does the app crash.
>
> Problem solved with no magic going on behind the user’s back :)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden