has_many conditions
Posted
by user305270
on Stack Overflow
See other posts from Stack Overflow
or by user305270
Published on 2010-03-30T17:24:08Z
Indexed on
2010/03/30
17:53 UTC
Read the original article
Hit count: 198
will-paginate
|ruby-on-rails
c = "(f.profile_id = #{self.id} OR f.friend_id = #{self.id})"
c += AND + "(CASE WHEN f.profile_id=#{self.id} THEN f.friend_id ELSE f.profile_id END = p.id)"
c += AND + "(CASE WHEN f.profile_id=#{self.id} THEN f.profile_rejected ELSE f.friend_rejected END = 1)"
c += AND + "(p.banned = 0)"
I need this to be used in a has_many relationship like this:
has_many :removed_friends, :conditions => ???
how do i set there the self.id?, or how do i pass there the id? Then i want to use the will_paginate plugin:
@profile.removed_friends.paginate(:page => 1, :per_page => 20)
Thanks for your help
© Stack Overflow or respective owner