开发者

Rails normalization of models

开发者 https://www.devze.com 2023-02-13 02:54 出处:网络
I\'m wondering how I can normalize my tables in rails, say I\'ve got a table containing id, username, email and an optional field (often left blank). I would like to m开发者_Go百科ove out this optiona

I'm wondering how I can normalize my tables in rails, say I've got a table containing id, username, email and an optional field (often left blank). I would like to m开发者_Go百科ove out this optional field into a separate table but still use it as a attribute in the model. Is this possible?


class Something
  belongs_to :other
  delegate :other_field, :to => :other, :allow_nil => true
end

Look at delegation: http://www.simonecarletti.com/blog/2009/12/inside-ruby-on-rails-delegate/

0

精彩评论

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