Forum: Ruby on Rails acts_as_list :scope with habtm

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.
38dd354b4ead6e6147ca4827b34c5965?d=identicon&s=25 Martin (Guest)
on 2007-07-17 23:34
(Received via mailing list)

I have a problem with a little more complex DB-schema.

My target are and sorted trees like this:
1 One
1.1 One.One
1.2 One.Two
2 Two

I use for it two models:
- top: This an item, with the name and position
- agenda: Collections of tops

class Agenda < ActiveRecord::Base
  has_and_belongs_to_many :tops

class Top < ActiveRecord::Base
  has_and_belongs_to_many :agendas
  acts_as_list  :scope => :parent_id
  acts_as_tree  :order => :position

Datebase tops:
id | parent_id | position | title
1  | 0         | 1        | One
2  | 0         | 2        | Two
3  | 1         | 1        | One.One
4  | 1         | 2        | One.Two

Looks like:

Works fine.

But my problem: The tops-database include tops for all agendas. So a
second agenda need also a new top with parent_id=0 and position=1:
5  | 0         | 1        | New One
... but acts_as_list used (sadly) correctly parent_id=0 and position=3

  acts_as_list  :scope => :parent_id + "correct agendas"

Which scope-option I need? Anyone can me help with the SQL-statement?

Or I must used acts_as_nested_set? Never used it. But there the same
problem with :scope and habtm-relationship, I think.

Thanks for help
38dd354b4ead6e6147ca4827b34c5965?d=identicon&s=25 Martin (Guest)
on 2007-07-20 19:40
(Received via mailing list)
Martin schrieb:

> I have a problem with a little more complex DB-schema.

Anybody an idea?
This topic is locked and can not be replied to.