I have a polymorphic table I am setting up between a model, let's call it Document, and a number of attributes that it has_many of. So I have a DocumentRelationship model and I wanted to write in this migration that the polymorphic attribute name would be "attribute". EG in the migration for DocumentRelationship I would add:
t.integer :attribute_id
t.string :attribute_type
Then, in the Document model I would say:
has_many :attributes, :polymorphic => true
has_many :authors, :through => :attributes, :source_type => "Author"
Or something like that.
Is it OK for me to name this field "attribute"? I know that you can't name a polymorphic field "object"; this leads to errors..
Thanks!
http://oldwiki.rubyonrails.org/rails/pages/ReservedWords
See the section which says: Other names that have been reported to cause trouble:
attributes – if you have a has_many called attributes, you can’t access to your object attributes anymore; only the associated objects
UPDATE: This link has more of the details https://github.com/walterdavis/railsready/wiki also see his heroku app which has search feature http://reservedwords.herokuapp.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With