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