Answer the question
In order to leave comments, you need to log in
How to get data on a condition linked to another table?
There are 3 models:
class Article < ActiveRecord::Base
has_many :facts
belongs_to :user
has_and_belongs_to_many :users
end
class Fact < ActiveRecord::Base
belongs_to :article
belongs_to :user
end
class User < ActiveRecord::Base
has_many :facts
has_many :articles
has_and_belongs_to_many :favorits, class_name: "Article"
end
Answer the question
In order to leave comments, you need to log in
In general, something like this:
@user.facts.
joins(:favorits). # = articles_users ?
where("facts.created_at > articles_users.created_at").
all
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question