• 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: EO: Should I create primary keys?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EO: Should I create primary keys?


  • Subject: Re: EO: Should I create primary keys?
  • From: Chuck Hill <email@hidden>
  • Date: Tue, 29 Jul 2003 10:50:17 -0700
  • Organization: Global Village Consulting, Inc.

As a general rule, if you are doing something in WO and it seems really difficult then you're doing it wrong.

:-)

Goodbye Bill wrote:
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.


--

Chuck Hill                                 email@hidden
Global Village Consulting Inc.             http://www.global-village.net

Progress is the mother of all problems.
- G. K. Chesterton
_______________________________________________
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.

  • Follow-Ups:
    • Re: EO: Should I create primary keys?
      • From: Arturo PĂ©rez <email@hidden>
References: 
 >Re: EO: Should I create primary keys? (From: Goodbye Bill <email@hidden>)

  • Prev by Date: Re: Saving entities problem [SOLVED]
  • Next by Date: Re: Correct "Logout" Action
  • Previous by thread: Re: EO: Should I create primary keys?
  • Next by thread: Re: EO: Should I create primary keys?
  • Index(es):
    • Date
    • Thread