#617 invalid
Lawrence Pit

:field vs :child_key value expectation

Reported by Lawrence Pit | October 27th, 2008 @ 05:06 PM

Defining a :field value for a property requires a string. I first tried with using a symbol, because that's what belongs_to expects when explicitely defining a :child_key. Doesn't feel consistent.


property :author, Integer, :field => "legacy_id"

belongs_to :book, :child_key => [:legacy_book_id]

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 28th, 2008 @ 12:43 AM

    • State changed from “new” to “invalid”

    The :field property option is a String because it's not the same thing as :child_key.

    The :field is the name of the container holding the property value in the storage engine. In the case of an RDBMS, the field would be equivalent to the table's column name. By default the :field is the same as the stringified property name, but it can be overridden in case you're using a legacy DB, or columns need special names (like CouchDB).

    The :child_key is the Array of property names to join with on the child side of the association. In a belongs_to() association, the child is the current model and the parent is the model the current one belongs to. It is an Array because a model's key can be one or more properties.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 28th, 2008 @ 01:49 PM

    If I understand you correctly, you're saying the :child_key=>[:supplier_id] bit is referring to another property in my model, and not directly to a table's column name? Even if such a property has not been explicitly defined in my model?

    That's correct. The option :child_key => [ :supplier_id ] instructs the belongs_to method to create a property named :supplier_id inside the current model and use that to connect to the parent model, which in this case is Organization because you specified the :class_name option.

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

Pages