Has_many dynamic conditions

Hello.
I have two models. Channel with last_access field and Item with
created_on field.
They are in one-to-many relation.
class Channel < ActiveRecord::Base
has_many :items
end
class Item < ActiveRecord::Base
belongs_to :channel
end

I want a second has_many relation in Channel, called :new_items which
created_on is newer than last_access. Something like that:
has_many :new_items, :class => “Item”, :conditions => ["items.created_on

?", last_access]
Unfortunately last_access method is taken from Channel:Class scope, not
from the Channel instance scope so i have a “undefined local variable or
method `last_access’ for Channel:Class”
Can i achieve my goals without using :finder_sql (i know it’ll work that
way) ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs