Forum: Ruby on Rails Magic Field Names - "position"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Arch S. (Guest)
on 2006-04-07 10:17
What does the Magic Field Name position do?

I was looking here:
http://wiki.rubyonrails.com/rails/pages/MagicFieldNames

And unfortunately that documentation is incomplete.

Thanks.
joey__ (Guest)
on 2006-04-07 10:37
Arch S. wrote:
> What does the Magic Field Name position do?
>
> I was looking here:
> http://wiki.rubyonrails.com/rails/pages/MagicFieldNames
>
> And unfortunately that documentation is incomplete.
>
> Thanks.

When using acts_as_list, it keeps track of the position of the item on
the list.

joey__
Arch S. (Guest)
on 2006-04-07 10:43
joey__ wrote:
> Arch S. wrote:
>> What does the Magic Field Name position do?
>>
>> I was looking here:
>> http://wiki.rubyonrails.com/rails/pages/MagicFieldNames
>>
>> And unfortunately that documentation is incomplete.
>>
>> Thanks.
>
> When using acts_as_list, it keeps track of the position of the item on
> the list.
>
> joey__


Can the list be specific to a belongs_to relationship?
Alex Y. (Guest)
on 2006-04-07 11:17
(Received via mailing list)
Arch S. wrote:
>>>
>>>Thanks.
>>
>>When using acts_as_list, it keeps track of the position of the item on
>>the list.
>>
>>joey__
>
>
>
> Can the list be specific to a belongs_to relationship?
Yes - use :order => :position in the belongs_to.
Alex Y. (Guest)
on 2006-04-07 11:27
(Received via mailing list)
Alex Y. wrote:
>>>>
>>
>>
>>
>> Can the list be specific to a belongs_to relationship?
>
> Yes - use :order => :position in the belongs_to.
>
D'oh...  Must not post before tea...

class Parent < AR::Base
   has_many :children, :order => :position
end

class Child < AR::Base
   acts_as_list, :scope => :parent
   belongs_to :parent, :order => :position
end
Arch S. (Guest)
on 2006-04-07 19:55
Alex Y. wrote:
> Alex Y. wrote:
>>>>>
>>>
>>>
>>>
>>> Can the list be specific to a belongs_to relationship?
>>
>> Yes - use :order => :position in the belongs_to.
>>
> D'oh...  Must not post before tea...
>
> class Parent < AR::Base
>    has_many :children, :order => :position
> end
>
> class Child < AR::Base
>    acts_as_list, :scope => :parent
>    belongs_to :parent, :order => :position
> end

Ahhh, that is cool.

One more question: what is the difference between specifying the :order
in belongs_to vs. has_many?  I would think you only need specify :order
in the has_many  declaration.  ??
Alex Y. (Guest)
on 2006-04-07 20:36
(Received via mailing list)
Arch S. wrote:
>>
>
>
> Ahhh, that is cool.
>
> One more question: what is the difference between specifying the :order
> in belongs_to vs. has_many?  I would think you only need specify :order
> in the has_many  declaration.  ??
Just looking at it, I can't think where it would be useful, but it's in
the docs as a supported option, so I suppose it must do something :-)
This topic is locked and can not be replied to.