Re: EO: Should I create primary keys?
Re: EO: Should I create primary keys?
- Subject: Re: EO: Should I create primary keys?
- From: Goodbye Bill <email@hidden>
- Date: Tue, 29 Jul 2003 00:35:43 -0400
Wow! How incredibly easy! Thanx, Guys!
I wish I could explain how incredibly difficult it is to "let go" of the
database after 20 years. Sometimes one cannot see the forest through the
trees, I guess.
=}~
On 20030728 2342, "Denis Stanton" <email@hidden> wrote:
>
> On Tuesday, July 29, 2003, at 01:38 PM, Goodbye Bill wrote:
>
>> Previously, I was creating the "Link" object and then setting a couple
>> of
>> foreign keys manually. Now, the keys of the "Link" object are not
>> exposed.
>> I'm assuming I'm supposed to add one object directly to the other and
>> let EO
>> handle the association. But how?
>
> After you set up the relationships in EOM you would gave generated Java
> classes which would include method for creating the links.
>
> Here's a tiny code sample. I have a Type table and a Vehicle table
> with a one-to-many relationship. i.e, many vehicles for each type.
>
> I create a new vehicle like this:
>
> public Vehicle createVehicleForType(Type type){
> Session session = (Session)session();
> Vehicle newVehicle = new Vehicle();
> session.defaultEditingContext().insertObject(newVehicle); //
> otherwise it won't get saved to database
>
> newVehicle.setVehicleName( "E type Jaguar" );
> < set other Vehicle instance variables >
>
> type.addToVehicles(newVehicle); // adds the vehicle to the
> array of vehicles for this type
> newVehicle.setType(type); // sets the foreign key in my Vehicle
> instance to point to my Type instance.
> session.saveChanges();
> }
>
> This is assuming that Vehicle has a relationship named "type", which
> causes EOM to generate a method
> public void setType(Type value) {
> takeStoredValueForKey(value, "type");
> }
>
> and Type has a method
> public void addToVehicles(Vehicle object) {
> includeObjectIntoPropertyWithKey(object, "vehicles");
> }
>
>
> Denis Stanton
> email@hidden
> Home: (09) 533 0391
> mobile: 021 1433622
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.