Forum: Italian Ruby user group Rails 4 relazioni condizioni parametri

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eff93e9bbe063b7136c9b6f218071a09?d=identicon&s=25 Marco Mastrodonato (marcomd)
on 2015-09-11 16:38
Ciao bagai,
c'รจ un modo per farlo direttamente nella relazione?

has_many   :relationships, -> (object, relation_date=Date.today) {
where("start_relation <= ?", relation_date) }

p=Person.first
p.relationships 1.month.ago

ho trovato questa soluzione ma non vorrei usare un campo fittizio es:

has_many   :relationships, -> (object) { where("start_relation <= ?",
object.dummy_date) }

p=Person.first
p.dummy_date = 1.month.ago
p.relationships

altrimenti uso uno scope e amen!
This topic is locked and can not be replied to.