Thats exactly what I was looking for! Thanks a lot Jeremy!
On Tuesday, May 10, 2016 at 5:37:15 PM UTC+2, Jeremy Evans wrote:
>
> On Tuesday, May 10, 2016 at 7:43:24 AM UTC-7, Petr Kaleta wrote:
>>
>> Hey everyone,
>> imagine we have this associated models:
>>
>> User one_to_many Likes
>> Photo one_to_many Likes
>>
>> I need to list all Photos related to a current user. So I need to show,
>> if photo was liked by current user.
>>
>> So I've extended Photo dataset with method like this
>>
>> ```
>> def personalized(user)
>> select_append(
>> Sequel.as(
>> Sequel.lit(
>> 'coalesce((SELECT TRUE FROM "likes" WHERE ("likes"."photo_id" =
>> "photos"."id" AND "likes"."user_id" == ?) LIMIT 1), FALSE)',
>> user.id
>> ),
>> :liked
>> )
>> )
>> end
>>
> ```
>>
>
> I think a virtual row would work best here:
>
> select_append do
> coalesce(DB[:likes].select(true).where(:likes__photo_id=>:photos__id,
> :likes__user_id=>user.id).limit(1), false).as(:liked)
> end
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.