Prev | Current Page 239 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


By default, the acts_as_nested_set method assumes that the foreign key column in your table
has a name of parent_id. If you use that column name, you do not need to specify it via the
parent_column attribute. But if you want to use a different name for your foreign key column,
you do need to specify that name via the parent_column attribute. For example, the following
example specifies a foreign key column name of realtedID:
class Comment < ActiveRecord::Base
acts_as_nested_set :parent_column => "related_id"
end
Keep in mind that the foreign key column named by the parent_column parameter is
intended to reference the parent record of the current record. If the current record is a root
record, the column??™s value should either be nil/null or set to a nonexistent key (probably
something like 0).
left_column
Use the left_column parameter to specify an alternative name for the left boundary column.
The left boundary column stores the lowest primary key value that the current record shares
a level with. By default, this column is assumed to be named lft.


Pages:
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251