Re: [Rails] Re: How to implement custom row ordering
On 16 May 2010 06:21, Albus Dumbledore <lists@ruby-forum.com> wrote:
> Well. I am having trouble understanding how acts_as_list works. I do not
> quite comprehend what the table schema for the example given by DHH must
> be:
>
> [code]
>
> class TodoList < ActiveRecord::Base
> has_many :todo_items, :order => "position"
> end
>
> class TodoItem < ActiveRecord::Base
> belongs_to :todo_list
> acts_as_list :scope => :todo_list
> end
>
> [/code]
>
> More precisely I wonder where should the `position` column go? To me it
> looks like it should go with the table having the foreign keys, i.e.
> `todo_items` table. Then it would seem that there would be no need for a
> `todo_lists` table, right? So it would be all about the todo_items
> table.
Yes; the position column goes on the table you want ordered.
The purpose of the todo_list table is to allow there to be more than
one list of items (if you want one). The "scope" field is a way of
identifying what separates the lists in the items table.
So if every user needs a list, then you can scope by user; if you're
only having one list of the items, then there's no need for a scope -
just position.
> It's scope that is bothering me. Firstly we can have our rows grouped
> by a foreign key (which seems trivial enough). However, what happens if
> it is a polymorphic reference, i.e. we need to use two columns to select
> a unique row?
Right.... your posting is suffering a little "feature creep" at the
moment. If you post what the limits are of the real problem you have,
then people can suggest solutions. If you have a complicated data
structure, then post some of the model code so we can all get our
heads around it.
>
> Thank you!
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home