You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2016/04/12 10:38:32 UTC
Fetching a list of objects from a list of primary keys
Hi all.
I have a list of primary keys [3,4,5,etc…] and I’d like to fetch all the corresponding objects in one go.
Do I have to expose the primary key of my entity to do this or is there some method like Cayenne.objectForPK() that can accept a list of keys and return multiple objects?
Cheers,
- hugi
Re: Fetching a list of objects from a list of primary keys
Posted by Hugi Thordarson <hu...@karlmenn.is>.
Great, thanks!
- hugi
> On 14. apr. 2016, at 08:50, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> Here is a shorter version:
>
> ExpressionFactory.inDbExp( User.ID_PK_COLUMN, 1, 2, 3)
>
>> On Apr 14, 2016, at 11:15 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>
>> Ah, of course, I can qualify on the DB path even if “id” is not a class attribute. Is this the correct way to go about this?
>>
>> new ASTIn( new ASTDbPath( User.ID_PK_COLUMN ), new ASTList( someListOfIDs() ) )
>>
>> Thanks,
>> - hugi
>>
>>
>>
>>> On 14. apr. 2016, at 06:34, Andrus Adamchik <an...@objectstyle.org> wrote:
>>>
>>> Actually a simple IN qualifier should work.
>>>
>>> Andrus
>>>
>>>> On Apr 12, 2016, at 11:38 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>>>
>>>> Hi all.
>>>> I have a list of primary keys [3,4,5,etc…] and I’d like to fetch all the corresponding objects in one go.
>>>> Do I have to expose the primary key of my entity to do this or is there some method like Cayenne.objectForPK() that can accept a list of keys and return multiple objects?
>>>>
>>>> Cheers,
>>>> - hugi
>>>
>>
>
Re: Fetching a list of objects from a list of primary keys
Posted by Andrus Adamchik <an...@objectstyle.org>.
Here is a shorter version:
ExpressionFactory.inDbExp( User.ID_PK_COLUMN, 1, 2, 3)
> On Apr 14, 2016, at 11:15 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
> Ah, of course, I can qualify on the DB path even if “id” is not a class attribute. Is this the correct way to go about this?
>
> new ASTIn( new ASTDbPath( User.ID_PK_COLUMN ), new ASTList( someListOfIDs() ) )
>
> Thanks,
> - hugi
>
>
>
>> On 14. apr. 2016, at 06:34, Andrus Adamchik <an...@objectstyle.org> wrote:
>>
>> Actually a simple IN qualifier should work.
>>
>> Andrus
>>
>>> On Apr 12, 2016, at 11:38 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>>
>>> Hi all.
>>> I have a list of primary keys [3,4,5,etc…] and I’d like to fetch all the corresponding objects in one go.
>>> Do I have to expose the primary key of my entity to do this or is there some method like Cayenne.objectForPK() that can accept a list of keys and return multiple objects?
>>>
>>> Cheers,
>>> - hugi
>>
>
Re: Fetching a list of objects from a list of primary keys
Posted by Hugi Thordarson <hu...@karlmenn.is>.
Ah, of course, I can qualify on the DB path even if “id” is not a class attribute. Is this the correct way to go about this?
new ASTIn( new ASTDbPath( User.ID_PK_COLUMN ), new ASTList( someListOfIDs() ) )
Thanks,
- hugi
> On 14. apr. 2016, at 06:34, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> Actually a simple IN qualifier should work.
>
> Andrus
>
>> On Apr 12, 2016, at 11:38 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>
>> Hi all.
>> I have a list of primary keys [3,4,5,etc…] and I’d like to fetch all the corresponding objects in one go.
>> Do I have to expose the primary key of my entity to do this or is there some method like Cayenne.objectForPK() that can accept a list of keys and return multiple objects?
>>
>> Cheers,
>> - hugi
>
Re: Fetching a list of objects from a list of primary keys
Posted by Andrus Adamchik <an...@objectstyle.org>.
Actually a simple IN qualifier should work.
Andrus
> On Apr 12, 2016, at 11:38 AM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>
> Hi all.
> I have a list of primary keys [3,4,5,etc…] and I’d like to fetch all the corresponding objects in one go.
> Do I have to expose the primary key of my entity to do this or is there some method like Cayenne.objectForPK() that can accept a list of keys and return multiple objects?
>
> Cheers,
> - hugi