开发者

Rails naming convention for Uppercase names

开发者 https://www.devze.com 2023-01-29 16:16 出处:网络
I\'ve got a model class: class QRCode < ActiveRecord::Base has_many :properties end So rails needs a database table named \'qr_codes\' and a foreign key called \'qr_code_id\'.

I've got a model class:

class QRCode < ActiveRecord::Base

  has_many :properties

end

So rails needs a database table named 'qr_codes' and a foreign key called 'qr_code_id'. But as a relationship in my Property Model it needs another na开发者_如何学JAVAme:

class Property < ActiveRecord::Base

  belongs_to :q_r_code

end

So if I want to create a Property object I' have to say ':q_r_code => qrcode' But active_record wants a qr_code property, because the column is called 'qr_code_id'

Do I understand something wrong or is this type of name impossible to map for Rails?

P.S.: I'm using Rails 3.0.3


belong_to accepts a :foreign_key and :class_name attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消