#1146 ✓not-applicable

Minor inconsistency with docs and reality on associations page regarding :model / :class_name

Reported by Docunext | December 7th, 2009 @ 05:30 AM



belongs_to :author, :model => 'User', :child_key => [ :post_id ]

should be:

belongs_to :author, :class_name => 'User', :child_key => [ :post_id ]

More info here => http://www.ruby.code-experiments.com/blog/2009/12/datamapper-associ...

Thanks for DataMapper!

Comments and changes to this ticket

  • Docunext

    Docunext December 7th, 2009 @ 05:31 AM

    • Title changed from “Minor inconsistency with docs and reality” to “Minor inconsistency with docs and reality on associations page regarding :model / :class_name”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 8th, 2009 @ 12:41 AM

    • State changed from “new” to “not-applicable”

    Actually, the :model option is the newer syntax. The :class_name option has been deprecated.

    In fact the preferred approach is to not pass the model name via the options anymore, but rather as the 2nd optional argument to belongs_to, eg:

      belongs_to :author, 'User', :child_key => [ :post_id ]

    The has() method can be passed the model name as the 3rd optional argument:

      has n, :authors, 'Author', :child_key => [ :post_id ]
  • MarkMT

    MarkMT December 8th, 2009 @ 03:56 AM

    Dan, why is that preferred? I think it makes the code harder to read.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket