• 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: Owen McKerrow <email@hidden>
  • Date: Tue, 15 Feb 2005 15:31:08 +1100

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().addObjectToBothSidesOfRelationship WithKey(newJoin,"classStudent");
((Class) tempClassList.objectAtIndex(i)).addObjectToBothSidesOfRelationshipWithKe y(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)).addObjectToBothSidesOfRelationshipWithK ey(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:

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


  • Follow-Ups:
    • Re: addObjectToBothSides... and setValue
      • From: Drew Thoeni <email@hidden>
    • Re: SOLVED addObjectToBothSides... and setValue
      • From: Drew Thoeni <email@hidden>
References: 
 >addObjectToBothSides... and setValue (From: Drew Thoeni <email@hidden>)

  • Prev by Date: addObjectToBothSides... and setValue
  • Next by Date: Re: SOLVED addObjectToBothSides... and setValue
  • Previous by thread: addObjectToBothSides... and setValue
  • Next by thread: Re: SOLVED addObjectToBothSides... and setValue
  • Index(es):
    • Date
    • Thread