Yes, it looks like willInsert has a rather poor choice of names.

Chuck

On 2015-02-12, 7:25 AM, "Theodore Petrosky" wrote:

BTW, here is an experiment. I put into my EO the three methods:

@Override
protected void init(EOEditingContext ec) {
System.out.println("Just called init ec = " + ec);

@Override
public void awakeFromInsertion(EOEditingContext editingContext) {
System.out.println("Just called awakeFromInsertion  ec = " + editingContext);

@Override
public void willInsert() {
System.out.println("Just called willInsert  ec = " + editingContext());


In my D2W app when I click the create new Event I see in the logs:

Just called init ec = er.extensions.eof.ERXEC@660922b0
Just called awakeFromInsertion ec = er.extensions.eof.ERXEC@660922b0

So now (in my D2W app) I am looking at the Create Event page and I select a 
Show and put in a date. When I click the Save button I see in the logs:

Just called willInsert ec = er.extensions.eof.ERXEC@660922b0


So willInsert is being called when you click the Save button. the EO is in an 
EC.

Is willInsert badly named and it should actually be called 
“willSaveEditingContext”?

Interesting from ERXEnterpriseObject.java:

 /**
     * 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 is wrong, I found validateForInsert():

    /**
     *  Calls up validateForInsert() on the class description if it supports it.
     * @throws NSValidation.ValidationException if the object does not
     *      pass validation for saving to the database.
     */
    @Override
public void validateForInsert() throws NSValidation.ValidationException {
        EOClassDescription cd = classDescription();
        if(cd instanceof ERXEntityClassDescription) {
            ((ERXEntityClassDescription)cd).validateObjectForInsert(this);
        }
        super.validateForInsert();
    }

oh yea, in EOCustomObject, validateForInsert calls validateForSave!

The more I dig into this, the more I am amazed at the complexity of the overall 
process, and that it is knowable, as there are people that truly understand the 
machinations.

On Feb 12, 2015, at 12:46 AM, Theodore Petrosky 
<[email protected]<mailto:[email protected]>> wrote:

Ramsey,

You called it EventDetail (maybe that’s a better name). I called it the 
EventBook.

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.

When I create an Event, I need to populate it with one EventDetail for each 
Book where the person is assigned to this book and the person is current (they 
could be fired) and the personBook is the PrimaryPlayer

In the app, I assign each person to the shows that they can work, I assign the 
instruments that they play. These are later used to limit the lists in 
different popups.

I know that I have been told that I should not do this in willInsert, but this 
is working. Actually, I have been told lots of things I should not do!!

This is in my Event.java.

It can not be done in the init() method as there is no show yet.

I create an array of books that are assigned to this.show().

@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 = null;
try {
aPerson = Person.fetchPerson(editingContext(), bookForPrimaryPersonQualifier);
} catch (Exception e) {
e.printStackTrace();
}

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(editingContext(), aBook, this);
eo.setPersonRelationship(aPerson);
} else {
EventBook.createEventBook(editingContext(), aBook, this);
}
bookForPrimaryPersonQualifier = Person.CURRENT.eq(true); //resetting the 
qualifier to base case
}
}

BTW, I am attaching my .eomodel if you want to look at it!

<Booking.eomodeld.zip>

On Feb 11, 2015, at 5:21 PM, Ramsey Gurley 
<[email protected]<mailto:[email protected]>> wrote:

I don’t see Person or EventBook in this model, but it’s mentioned in your code. 
Seems like you’re leaving out something important.

On Feb 11, 2015, at 2:15 PM, Theodore Petrosky 
<[email protected]<mailto:[email protected]>> wrote:

what I am trying to accomplish is assign to the entity Event all the Books that 
are assigned to the show.

so    Event toOne Show toMany Book

When I create a new Event, I assign the Show and a Date.

Person current() is a boolean and true means he gets assigned to a book? Can 
there be more than one Person who is current() for a show/event/book/the whole 
person table?? What is in EventBook?

I think what’s happening here is D2W builds an app based on your model, but 
your model doesn’t properly reflect what you are trying to capture.

Perhaps you should have a schema like

Event
->Show
->>EventDetail
-Date

EventDetail
->Person
->Book
->Event

Then your report is just listing this detail table grouped by event date. When 
you create an event, that is the Master object and these are the details. So 
your D2W layout could look like

QueryEvent: D2WQuery so you can query by date ranges
SelectEvent: D2WSelect (D2WPick for multiple events) so you can choose which 
event(s) are reported
EventDetail: D2WGroupingList grouped by event.date

Or just query and list events grouped by date, then have a nested list for 
Person and/or Book in that table.

Or something else.

TL;DR, if you’re fighting D2W, your model probably stinks :-)




 _______________________________________________
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]

Reply via email to