Forum: Ruby on Rails Reaching through a belongs_to for acts_as_list scope?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Eric N. (Guest)
on 2006-06-11 04:56
(Received via mailing list)
I'm running into a situation where I'd like to provide the list scope
for an acts_as_list model from one step removed. In minimalistic form
(with several other associations removed from each level).

class MainEntity < AcrtiveRecord::Base
   has_many :containers

class Container < ActiveRecord::Base
   has_many :elements
   belongs_to :main_entity

class Elements < ActiveRecord::Base
   belong_to :containers
   acts_as_list :scope=>  ???  # it wants to be container.main_entity_id

Now I've thought of two ways to solve this.
   1.  add main_entity_id to the Element -- this adds a redundant
link in the DB, and I'd like to avoid that, but if this is the normal
Rails solution, I guess I can live with it...

  2. Something like
     acts_as_list :scope=>'container_id IN (#
{ { |c|}.join(",")})'

appears to work, but also appears a little cumbersome.

Is there a better way?

This topic is locked and can not be replied to.