Multiple Table Inheritance vs. Single Table Inheritance in Ruby on Rails

前端 未结 4 727
天命终不由人
天命终不由人 2020-12-23 11:08

I have been struggling for the past few hours thinking about which route I should go. I have a Notification model. Up until now I have used a notification_type column to ma

4条回答
  •  温柔的废话
    2020-12-23 11:26

    has_one :details, :class_name => "#{self.class.name}Detail"
    

    doesn't work. self.class.name in the context of a class definition is 'Class' so :class_name is always 'ClassDetail'

    So it must be:

    has_one :details, :class_name => "#{self.name}Detail"
    

    But very nice idea!

提交回复
热议问题