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
```

which works pretty well, but really don't like this vanilla SQL way. Any 
hints how to do it pure and clean Sequel way?

Thanks

-- 
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.

Reply via email to