0

의 당신이 다형성과 같은 관계가 있다고 가정 해 봅시다 :다형성 관계 - 형식 특성에 저장되는 내용은 무엇입니까?

class Picture < ActiveRecord::Base 
    belongs_to :imageable, polymorphic: true 
end 

class Employee < ActiveRecord::Base 
    has_many :pretty_pictures, as: :imageable 
end 

class ProductInvoice < ActiveRecord::Base 
    has_many :pretty_pictures, as: :imageable 
end 

을 그리고이 그림의 모델에 대한 마이그레이션입니다 :

class CreatePictures < ActiveRecord::Migration 
    def change 
    create_table :pictures do |t| 
     t.string :name 
     t.references :imageable, polymorphic: true 
     t.timestamps 
    end 
    end 
end 

의 당신이와 @product_invoice 있다고 가정 해 봅시다 : 1의 ID를하고 이 제품에 속한 @ 사진이 있습니다. @ picture.imagable_id가 1과 같아야한다는 것을 알고 있지만 @ picture.imagable_type에 저장된 값은 무엇입니까?

  • 'ProductInvoice'
  • 'ProductInvoices'
  • 'product_invoice'
  • 'product_invoices'
  • 의견에 G.B를 통해
+1

'ProductInvoice' –

답변

0

'ProductInvoice'

관련 문제