On Monday, November 19, 2012 7:26:51 PM UTC-8, Stefan Rohlfing wrote:
>
> You probably don't want to add friends as an association. I would use a
>> simple method:
>>
>> class User < Sequel::Model
>> def friends
>> follows & followers
>> end
>> end
>>
>> since friends appears to be the intersection of follows and followers.
>>
>
> Thanks for this simple and elegant implementation. However, I am still
> interested to know I could achieve the same result using an association. Or
> would you in this case just write the raw SQL query?
>
>
You could probably use an custom association if you wanted to:
User.many_to_many :friends, :class=>User,
:dataset=>proc{User.join(:relationships___ru, :user_id =>
:nickname).join(:relationships___rf,
:follower_id=>:users__nickname).where(:ru__follower_id=>nickname,
:rf__user_id=>nickname)}
Writing an eager loader for the association is left as an exercise to the
reader. :)
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/t7LqBGmjiBAJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.