Hi Dan,
On Jan 7, 2008, at 3:06 PM, Daniel KvasniÄka jr. wrote:
> Hi people,
> I would like to add an object to a M:N relationship. Cayenne generated
> those convenience methods starting with "addTo". These take DataObject
> as a parameter and I noticed that it has to be a context-registered
> object -- correct?
Correct.
> So if I have a collection of primary keys that correspond to primary
> keys of objects I want to add to the relationship, I need to fetch
> those objects for those PKs and then add them to the relationship --
> correct?
> Is it possible to add a object only on the basis of it's PK? Or do I
> need to fetch the data first to ensure the object I want to bind is
> still valid?
You can create a fault for an object without doing a DB fetch (if you
are absolutely sure that each PK is valid):
int pk;
ObjectId id = new ObjectId("MyEntity", "PK_COLUMN", pk);
Object o = context.localObject(id, null); // no query will happen
here
But since Cayenne sets up a reverse relationship, the object will be
resolved once you add it to the relationship:
Object m;
m.addToSomeRelationship(o); // a query will be run here to connect
"o" back to "m"
So you might just resolve all your objects yourself anyways (at least
you can batch that operation to make it efficient).
Andrus
This archive was generated by hypermail 2.0.0 : Mon Jan 07 2008 - 08:49:22 EST