Discussion:
Display PrimaryKey
Peter Müller
2011-07-13 10:01:34 UTC
Permalink
Hello together,

i've a question about primary keys in WebObjects: I have a model like this:
id (Integer), no accessor, primary key
lastname (String), accessor
firstname (String), accessor
...

The id's will be needed in an PDF-Download (the people working with them need the ID, I don't know why, but they need this ID).

Because there is no accessor to this id, i can't display it. Is there a way, to display the ID (i don't want to modify, just display)?

Thank you a lot,
Peter M.
--
NEU: FreePhone - kostenlos mobil telefonieren!
Jetzt informieren: http://www.gmx.net/de/go/freephone
Maik Musall
2011-07-13 10:33:35 UTC
Permalink
public Integer pk() {
try {
return (Integer) EOUtilities.primaryKeyForObject( this.editingContext(), this ).objectForKey( "id" );
} catch (Exception e ) {
return null;
}
}

The exception would occur on unsaved objects as it doesn't have a primary key yet.

But consider adding a unique id to the EO other than the primary key, which you then could make a normal attribute. You shouldn't expose the primary key to the outside. If you one day need to migrate the database somewhere else, chances are the primary key will change. An additional attribute could stay the same. Plus you can set and determine that attribute on unsaved objects, too.

Maik
Post by Peter Müller
Hello together,
id (Integer), no accessor, primary key
lastname (String), accessor
firstname (String), accessor
...
The id's will be needed in an PDF-Download (the people working with them need the ID, I don't know why, but they need this ID).
Because there is no accessor to this id, i can't display it. Is there a way, to display the ID (i don't want to modify, just display)?
Thank you a lot,
Peter M.
--
NEU: FreePhone - kostenlos mobil telefonieren!
Jetzt informieren: http://www.gmx.net/de/go/freephone
Paul D Yu
2011-07-13 10:37:51 UTC
Permalink
Peter

If you are using wonder, you should be able to just call person().primaryKey().

Paul

Sent from my iPad
Post by Peter Müller
Hello together,
id (Integer), no accessor, primary key
lastname (String), accessor
firstname (String), accessor
...
The id's will be needed in an PDF-Download (the people working with them need the ID, I don't know why, but they need this ID).
Because there is no accessor to this id, i can't display it. Is there a way, to display the ID (i don't want to modify, just display)?
Thank you a lot,
Peter M.
--
NEU: FreePhone - kostenlos mobil telefonieren!
Jetzt informieren: http://www.gmx.net/de/go/freephone
Johann Werner
2011-07-13 13:17:53 UTC
Permalink
have a look at

ERXEnterpriseObject.primaryKey() (will return null for unsaved objects as the pk does not yet exist)
ERXEnterpriseObject.primaryKeyInTransaction() (will get a pk from database if it does not yet have one)

jw
Post by Paul D Yu
Peter
If you are using wonder, you should be able to just call person().primaryKey().
Paul
Sent from my iPad
Post by Peter Müller
Hello together,
id (Integer), no accessor, primary key
lastname (String), accessor
firstname (String), accessor
...
The id's will be needed in an PDF-Download (the people working with them need the ID, I don't know why, but they need this ID).
Because there is no accessor to this id, i can't display it. Is there a way, to display the ID (i don't want to modify, just display)?
Thank you a lot,
Peter M.
--
NEU: FreePhone - kostenlos mobil telefonieren!
Jetzt informieren: http://www.gmx.net/de/go/freephone
Loading...