ruby on rails - How select users where with paid is true and paid_subscriptions expirence_at current date? -


i have model user

has_many: paid_subscriptions 

model paidsubscription

belongs_to :user 

how me write active record query select users, paid true , paid_subscriptions expirence_at < current day?

edit:

user.includes(:paid_subscriptions).where("year(created_at) = ? , active = ?", 2011, true).where('paid_subscriptions.expirence_at < ?', date.today) 

you can try following:

user.includes(:paid_subscriptions)     .where('year(users.created_at) = ? , users.active = ? , paid_subscriptions.expirence_at < ?', 2011, true, date.today) 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -