Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I name a rails attribute "attribute?"

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!

like image 308
jay Avatar asked Dec 05 '25 10:12

jay


1 Answers

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/

like image 143
uday Avatar answered Dec 08 '25 01:12

uday



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!