You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by David Feshbach <dj...@gmail.com> on 2013/03/06 18:38:11 UTC
Get ObjectId of To-One Relationship Without Faulting
Is there any way to get the ObjectId or raw foreign key of a related object without faulting? I'd like to implement getArtistObjectId() or getArtistPK() without calling getArtist().getObjectId() or Cayenne.longPKForObject(getArtist()).
Thanks,
David
Re: Get ObjectId of To-One Relationship Without Faulting
Posted by David Feshbach <dj...@gmail.com>.
You're right. I'm not sure how I missed that. I think when I tried it a few weeks ago something else was causing the object to get resolved and I just assumed it was the getter. Anyway, I found a "workaround" by calling getObjectContext().performQuery(new RelationshipQuery(getObjectId(), "artist", false)). I'll probably change it back.
Thanks,
David
On Mar 7, 2013, at 2:43 AM, Andrus Adamchik wrote:
> getArtist().getObjectId() or Cayenne.longPKForObject(getArtist()) actually will not result in a DB round-trip. Cayenne returns a HOLLOW object for simple to-one relationships. So this is the Cayenne way.
>
> If this doesn't work, could you please elaborate why you need a raw FK. Maybe there's another way.
>
> Andrus
>
>
> On Mar 6, 2013, at 8:38 PM, David Feshbach <dj...@gmail.com> wrote:
>> Is there any way to get the ObjectId or raw foreign key of a related object without faulting? I'd like to implement getArtistObjectId() or getArtistPK() without calling getArtist().getObjectId() or Cayenne.longPKForObject(getArtist()).
>>
>> Thanks,
>>
>> David
>
Re: Get ObjectId of To-One Relationship Without Faulting
Posted by Andrus Adamchik <an...@objectstyle.org>.
getArtist().getObjectId() or Cayenne.longPKForObject(getArtist()) actually will not result in a DB round-trip. Cayenne returns a HOLLOW object for simple to-one relationships. So this is the Cayenne way.
If this doesn't work, could you please elaborate why you need a raw FK. Maybe there's another way.
Andrus
On Mar 6, 2013, at 8:38 PM, David Feshbach <dj...@gmail.com> wrote:
> Is there any way to get the ObjectId or raw foreign key of a related object without faulting? I'd like to implement getArtistObjectId() or getArtistPK() without calling getArtist().getObjectId() or Cayenne.longPKForObject(getArtist()).
>
> Thanks,
>
> David