• 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: Getting the Primary Key From A Method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the Primary Key From A Method


  • Subject: Re: Getting the Primary Key From A Method
  • From: Art Isbell <email@hidden>
  • Date: Tue, 17 Dec 2002 13:17:05 -1000

On Tuesday, December 17, 2002, at 12:31  PM, Jonathan Fleming wrote:

I have this code that I want to extract the ID from but it is
eluding me how to get it.
I'm usually getting my ID from a WODirect action with code such as
this:
// set object ID for Selected page
       Application anApp = Application.myApplication();
       anApp.setTbJobPicID( (String)this.request().formValueForKey
( "tbJobPicID" ) );

but now I am using state and can not think how to extract it as the
Direct action code would not work in this method that I am trying to
get the ID from:

I'm confused. If you are able to extract tbJobPicID from a form using a Direct Action, then tbJobPicID had to be in this form. If it's in the form, why can't you bind an instance variable of the component to a key of the dynamic element that contains tbJobPicID?


public WOComponent dbAddTbJobLinkToClientRelationship() {
       // get editing context
       EOEditingContext ec = session().defaultEditingContext();
       // create new tbJob object
       TbJob newTbJob = new TbJob();
       newTbJob.setTextAboutJob("Sorry, information about this job
has not been entered yet");
       // insert new tbJob into editing context
       ec.insertObject(newTbJob);
       // add new tbJob to tbJobs and set tbClient for it
       tbClient.addObjectToBothSidesOfRelationshipWithKey
(newTbJob, "tbJobs");
       setTbJobID(/*I want to get primary key here*/);

The primary key of what? But why are you accessing primary keys at all? Usually, EOF manages primary keys behind the scenes. Primary and foreign keys are relational database artifacts; enterprise and relationship objects are what the usual EOF code manipulates. Primary and foreign keys are typically NOT class properties in one's eomodel, so they're not accessible from one's Java code.


If you want to maintain an object handle, consider using its global ID rather than its primary key (EOEditingContext.globalIDForObject(EOEnterpriseObject)). You might not want to access an object's global ID unless it was fetched from an external store or until a new object is saved to one. A new object can have a temporary global ID which I believe is replaced by a permanent one upon saving (not sure of the details).

If you simply must access the primary key, see EOUtilities.primaryKeyForObject(EOEditingContext, EOEnterpriseObject).

Art
_______________________________________________
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.

References: 
 >Getting the Primary Key From A Method (From: "Jonathan Fleming" <email@hidden>)

  • Prev by Date: Re: NSKeyValueCoding$Null
  • Next by Date: WebObjects On Windows Running Problem
  • Previous by thread: Getting the Primary Key From A Method
  • Next by thread: EO Raw Row Query
  • Index(es):
    • Date
    • Thread