Re: SOLVED addObjectToBothSides... and setValue
Re: SOLVED addObjectToBothSides... and setValue
- Subject: Re: SOLVED addObjectToBothSides... and setValue
- From: Drew Thoeni <email@hidden>
- Date: Mon, 14 Feb 2005 23:36:02 -0500
Of course, thanks. I've been staring at the hidden table for about a
half-hour. It's always obvious once someone points it out to you.
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