0
継承されたクラスを持っているときに逆多型関連付けを行うのに問題があります。誰が何が起こっているのか知っていますか?継承クラスでポリモフィック・レール結合が失敗しますか?
ruby-1.9.2-rc2 > Label.first
=> #<Label id: 1, owner_id: 1, owner_type: "Student", name: "Lorem", created_at: "2011-01-23 05:02:29", updated_at: "2011-01-23 05:02:29">
ruby-1.9.2-rc2 > Label.first.owner
=> #<Student id: 1, email: "[email protected]", ..., avatar_updated_at: nil>
ruby-1.9.2-rc2 > Label.first.owner.labels
=> []
class Student < User
has_many :labels, :as => :owner
class Label < ActiveRecord::Base
belongs_to :owner, :polymorphic => true
注:ちょうど良い測定のため(これは何が違うが、念のためにあるべきではないことを...)それでも
User.find(1).labels
=> []
また
l = Label.find(4)
=> #<Label id: 4, owner_id: 2, owner_type: "Student", name: "sit", created_at: "2011-01-23 05:02:29", updated_at: "2011-01-23 05:02:29">
ruby-1.9.2-rc2 > l.owner_type = "User"
=> "User"
ruby-1.9.2-rc2 > l.save
=> true
ruby-1.9.2-rc2 > Student.find(2).labels
=> [#<Label id: 4, owner_id: 2, owner_type: "User", name: "sit", created_at: "2011-01-23 05:02:29", updated_at: "2011-01-23 07:13:37">]