My models look like this:
class Post < ActiveRecord::Base
has_many :aspect_visibilities, :as => :shareable, :primary_key => :guid, :foreign_key => :shareable_guid
has_many :aspects, :through => :aspect_visibilities
end
class AspectVisibility < ActiveRecord::Base
belongs_to :aspect
validates_presence_of :aspect
belongs_to :shareable, :polymorphic => true, :primary_key => :guid, :foreign_key => :shareable_guid
validates_presence_of :shareable
end
class Aspect < ActiveRecord::Base
has_many :aspect_visibilities
has_many :posts, :through => :aspect_visibilities, :source => :shareable, :source_type => 'Post'
end
My problem is that when I insert a Post into an Aspect the id of the Post is inserted into the AspectVisibility as the Post's key. But actually the Post's guid should be inserted.
I have seen solutions like this:
class Post < ActiveRecord::Base
set_primary_key :guid
[...]
end
But I do not want to change the foreign key of Posts in general, but just for the AspectVisibility association.
Can anybody tell me how to do this?
Thanks!