This has me scratching my head:
a Person has many Things
a Person has many Collections
a Collection has many Things
…Things in a Collection are ordered
…Things in a Collection can be related to (created by) any User
…a collection has additional attributes, such as a name etc
I am confused about habtm in rails (especially when using
acts_as_habtm_list) vs. going the :through route. Please tell me I am
thinking too hard!
My current take:
--------
class Person < ActiveRecord::Base
has_many :things
has_many :collections
end
class Thing < ActiveRecord::Base
belongs_to :person
has_and_belongs_to_many :collections, :order => ‘position’
end
class Collection < ActiveRecord::Base
belongs_to :person
has_and_belongs_to_many :thing_collections, :order => ‘position’
end
class ThingCollection < ActiveRecord::Base
has_and_belongs_to_many :collections
has_and_belongs_to_many :things
acts_as_list :scope => :collections
end
--------
Is that right?
or is it better to do something like this:
-----*-
class Person < ActiveRecord::Base
has_many :things
has_many :collections
end
class Thing < ActiveRecord::Base
belongs_to :person
belongs_to :collection
has_many :collections, :through => :thing_collections, :order =>
“position”
end
class Collection < ActiveRecord::Base
belongs_to :person
has_many :things, :through => :thing_collections, :order =>
“position”
end
class ThingCollection < ActiveRecord::Base
belongs_to :collections
belongs_to :things
acts_as_list :scope => :collection_id
end
------
Yes, I am in over my head.
Yes, I am smart, and willing to learn.
Yes, I want to built something that will last and be flexible…
No, I haven’t even moved on past the model, because I wish to
understand…
Thanks!
sudara