I have 2 models:
User and Book
and a join model ownership which connect User and Book
class Book < ActiveRecord::Base
has_many :ownerships
has_many :users, :through => :ownerships,:uniq=>true
...
end
class User < ActiveRecord::Base
has_many :ownerships
has_many :books, :through => :ownerships
end
class Ownership < ActiveRecord::Base
belongs_to :user
belongs_to :book
end
The scenario is that when user A is searching for books on my website,I return the related books which are owned by users around user A(for example,they are both in the same university).
Can I do that with rails accociation?
thanks @Mark Guk
what i finally do is :