• 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
Re: why ec.refreshAllObjects() required?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why ec.refreshAllObjects() required?


  • Subject: Re: why ec.refreshAllObjects() required?
  • From: Drew Thoeni <email@hidden>
  • Date: Tue, 22 Feb 2005 17:50:18 -0500

Weide,

Normally, I would have used the flattened relationship. However, in these cases, I have data that also needs to be recorded for each of the many-to-many relationships. My knowledge of database design, and the views of others on the list, suggested that unflattening the table was the way to go.

You are correct, before I unflattened the table and added these other attributes, the update of the ec worked as expected. I can tell the ec is not updating because when I go to remove these relationships, the ec does not generate any SQL, my assumption is that the ec does not think anything has to be done. To confirm this, I added the refreshAllObjects and the code works.

regards,

Drew

On Feb 22, 2005, at 7:44 AM, Weide, Björn wrote:

Hi Drew,
 
I am not sure how you determine that the ec is not updated. Your problem seems to be that you create join-table-objects directly. Imho the edc dont gets all notifications in this case, so if you ask student for his classes, probably the flattened relationship was not refreshed by your save. You should try setting the values via flattened relationships.
 
Hope it helps,
Björn
-----Original Message-----
From: Drew Thoeni [mailto:email@hidden]
Sent: Tuesday, February 22, 2005 1:01 PM
To: WOdev List
Subject: why ec.refreshAllObjects() required?



I have some code (below) that adds to two many-to-many relationships. I can run it once (and it's twin that removes these entries) and it works just fine. But, when I run it the second time, the tables get updated but the ec does not. When I add the line "ec.refreshAllObjects()" I can then add and remove the relationships as many times as I want and all is well in the tables and ec.




Generally when I find a situation like this I attribute it to my shallow understanding of WO. If it is critical or mysterious enough, I ask the all-knowing list. Occasionally it turns out to be some oddity in WO. Which is it here?



 Regards,



 Drew



// Note: This method is resides in the "Class" table (an unfortunate name) and is called from



public void joinClass(EOEditingContext ec, Application application, Session session) {

        // This method adds a student to class (inserts a row into ClassStudent) and

        // Adds an entry into BookStudent for each book this student has for this class.



        // this step-by-step join is to allow awakeOnInsertion to set variables in this unflattened table.

        ClassStudent newGPJoin = (ClassStudent)EOUtilities.createAndInsertInstance(ec,"ClassStudent");

        session.currentStudent.addObjectToBothSidesOfRelationshipWithKey(newGPJ oin,"classStudents");

        this.addObjectToBothSidesOfRelationshipWithKey(newGPJoin, "classStudents");

        

        // add relationship into table BookStudent, student to each book, and set class number.

        NSArray tempBookList = this.books();

         int count = tempBookList.count();

         Book tempBookItem = (Book)tempBookList.objectAtIndex(0);

         for(int i = 0 ; i < count ; i++) {

         //Make a new bookStudent Object

        BookStudent newCPJoin = (BookStudent)EOUtilities.createAndInsertInstance(ec,"BookStudent");

         newCPJoin.setClassNumber(this.classNumber());

        session.currentStudent.addObjectToBothSidesOfRelationshipWithKey(newCPJ oin,"bookStudents");

        ((Book)tempBookList.objectAtIndex(i)).addObjectToBothSidesOfRelationshi pWithKey(newCPJoin, "bookStudents");

         }

         ec.saveChanges();

        ec.refreshAllObjects(); // WITHOUT THIS LINE, CODE WILL NOT WORK REPEATEDLY.

         this.embargoClassIfNeeded(ec, application, session);   

}

_______________________________________________ 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
  • Prev by Date: Re: strange enum error
  • Next by Date: Re: why ec.refreshAllObjects() required?
  • Previous by thread: Re: why ec.refreshAllObjects() required?
  • Next by thread: Re: why ec.refreshAllObjects() required?
  • Index(es):
    • Date
    • Thread