Magic Field Names - "position"


#1

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.


#2

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__


#3

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?


#4

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. ??


#5

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


#6

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:


#7

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.