Magic Field Names - "position"

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.

Arch S. wrote:

What does the Magic Field Name position do?

I was looking here:
Peak Obsession

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__

joey__ wrote:

Arch S. wrote:

What does the Magic Field Name position do?

I was looking here:
Peak Obsession

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. 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. 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. 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 :slight_smile:

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.