• 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: addObjectToBothSides... and setValue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: addObjectToBothSides... and setValue


  • Subject: Re: addObjectToBothSides... and setValue
  • From: Drew Thoeni <email@hidden>
  • Date: Mon, 14 Feb 2005 23:40:15 -0500

Ooops. Spoke too soon. One quick question... I'm assuming the newJoin object below represents the new row that will be inserted and I can update that object prior to saving. While I get I can update via awakeFromInsertion for defaults, some of the columns in this table are derived, not default.

regards,

Drew



On Feb 14, 2005, at 11:31 PM, Owen McKerrow wrote:

Drew,

If you are adding more info to your join table than just the ID's of the other 2 tables then you won't be able to use Flattened relationships, which is what Im assuming you are doing. That's how your addObjectToBothSidesOfRelationship is working, it is creating the join table object for you, thats why you never see it.

You would have to change the code to something like :

NSArray tempClassList = schoolItem.classes();
int count = tempClassList.count();
Class tempClassList = (Class) tempClassList.objectAtIndex(0);
for(int i = 0 ; i < count ; i++) {
//Make a new classStudent Object
//Note you can override ClassStudents awakeFromInsertion method to set up any default values.
ClassStudent newJoin = (ClassStudent) EOUtilities.createAndInsertInstance(ec,"ClassStudent");
((Session)session()).currentStudent().addObjectToBothSidesOfRelationshi pWithKey(newJoin,"classStudent");
((Class) tempClassList.objectAtIndex(i)).addObjectToBothSidesOfRelationshipWithK ey(newJoin, "classStudent");
}
ec.saveChanges();


Owen

On 15/02/2005, at 2:56 PM, Drew Thoeni wrote:

I'm setting the relationship between a student and his classes. This is a many-to-many join (students to classes) so I'm interating through to set each relationship. I suppose that's correct.

Background: I'd also like to set a value on the newly inserted relationship row. For example, I have a lastAttemptedContactTime in this many-to-many join so I know when I last sent an email to this student for this class.

Question: How to easily set a value for each item in the many-to-many? I may be missing something here, but at the time the relationship is set, I don't think I have a classStudent (the many-to-many object) available to me. Or is there a way to have that object in hand so I could then just set the value?

Regards,

Drew

NSArray tempClassList = schoolItem.classes();
int count = tempClassList.count();
Class tempClassList = (Class) tempClassList.objectAtIndex(0);
for(int i = 0 ; i < count ; i++) {
((Class) tempClassList.objectAtIndex(i)).addObjectToBothSidesOfRelationshipWith Key(session.currentStudent, "students");
}
ec.saveChanges();
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden
Owen McKerrow
WebMaster, emlab
http://emlab.uow.edu.au

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"As of tomorrow, employees will only be able to access the building using individual security cards. Pictures will be taken next Wednesday employees will receive their cards in two weeks."
- "Dilbert Quotes" Winner, Fred Dales, Microsoft Corp




_______________________________________________ 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
References: 
 >addObjectToBothSides... and setValue (From: Drew Thoeni <email@hidden>)
 >Re: addObjectToBothSides... and setValue (From: Owen McKerrow <email@hidden>)

  • Prev by Date: Re: SOLVED addObjectToBothSides... and setValue
  • Next by Date: Re: Direct Action App Editing Context management?
  • Previous by thread: Re: SOLVED addObjectToBothSides... and setValue
  • Next by thread: Web page design in WO
  • Index(es):
    • Date
    • Thread