so are you suggesting that awakeFromInsertion is the correct place to assign these entities? I actually assumed that there was an editingContext at this point. And you know what they say about assuming.
If I put my code in awake from insertion, I then call “editingContext().saveChanges” at the end? On Feb 11, 2015, at 11:21 AM, Chuck Hill <[email protected]> wrote: > Doing anything to an EO when it is not in an EC (e.g. Before it is inserted) > seems like a Very Bad Idea. EOF is not expecting this. > > Chuck > > > On 2015-02-11, 8:17 AM, "Theodore Petrosky" wrote: > > but (and I will test this assumption) isn’t awakeFromInsertion called AFTER > the insertion? and willInsert Before? > > I need to assign these relationships BEFORE the main EO is inserted. So in my > case, I want to relate all the BOOKS that belong to the Show, then assign the > PrimaryPlayer to the books. > > As I said, I will confirm the order of events with some tests. > > The next question is the exception. If two people are marked PrimaryMusician > ( which is an operator error ), I want to throw an exception and tell the > user, “Sorry, could not assign person to Viola as two people are marked > “Primary Player”! (Jane Doe, Peter Simpson) > > > On Feb 11, 2015, at 10:49 AM, Samuel Pelletier <[email protected]> wrote: > > Theodore, > I think your code would be in a better place in the awakeFromInsertion > instead of willInsert. > awakeFromInsertion is called only once when the EO is created. My > understanding is willInsert is called when a EO will be saved the first time > by an EOEditingcontext. > Samuel > Le 2015-02-10 à 09:13, Theodore Petrosky <[email protected]> a écrit : > I am in the process of creating an example d2w app. Basically it manages > Shows and the People that play them. the end result is a report for any given > week and specific show, who played what book? > So I can create shows, people, instruments. and I am looking at the Events. > An event is a performance. It needs a show, and date/time (there could be > multiple performances on any given day). > So I create an Event, and I need to pick up all the books that belong to the > Show and the people that are the Primary players of the book. > My solution was to use the willInsert() in the EO: > @Override > public void willInsert() { > super.willInsert(); > EOQualifier bookForPrimaryPersonQualifier = Person.CURRENT.eq(true); > bookForPrimaryPersonQualifier = ERXQ.and(bookForPrimaryPersonQualifier, > Person.PERSON_BOOKS.dot(PersonBook.IS_PRIMARY_PLAYER.eq(true))); > EOQualifier booksAssignedToShowQualifier = Book.SHOW.eq(this.show()); //all > the books for this show > NSArray<Book> booksForThisEvent = Book.fetchBooks(editingContext(), > booksAssignedToShowQualifier, null); > for (Book aBook: booksForThisEvent) { > bookForPrimaryPersonQualifier = ERXQ.and(bookForPrimaryPersonQualifier, > Person.PERSON_BOOKS.dot(PersonBook.BOOK.eq(aBook))); > Person aPerson = Person.fetchPerson(this.editingContext(), > bookForPrimaryPersonQualifier); > if (aPerson != null) { //if there is a primary person applied to this book, > assign him/her to the EventBook else it's null! > EventBook eo = EventBook.createEventBook(this.show().editingContext(), aBook, > this); > eo.setPersonRelationship(aPerson); > } else { > EventBook.createEventBook(this.show().editingContext(), aBook, this); > } > bookForPrimaryPersonQualifier = Person.CURRENT.eq(true); //resetting the > qualifier to base case > } > } > Am I stepping on myself doing this in the EO and willInsert? > and > I need help with throwing an exception. if there are two people assigned as > the primary player of a given book, of course it blows up. > Person aPerson = Person.fetchPerson(this.editingContext(), > bookForPrimaryPersonQualifier); > Assuming that the willInsert() method is okay to do, what’s the correct way > to surround this with a try/catch and throw the exception. Obviously, if I > just surround it with the try/catch like this: > Person aPerson = null; > try { > aPerson = Person.fetchPerson(this.editingContext(), > bookForPrimaryPersonQualifier); > } catch (Exception e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > the insertion will succeed assigning no one to the offending book. > I can only hope that willInsert passes muster! > 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/samuel%40samkar.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/chill%40gevityinc.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]
