ruby - Rails polymorphic table that has other kinds of associations -


i'm modeling rails 3.2 app , need polymorphic association named "archivable" in table named "archives". no worries it, "archives" table must belongs_to "connections" table. want know if there's constraints rails that.

you can see model here

another detail, connection model has twice user_id foreign key. user_id sender , user_is receiver. possible? think did below won't work...

here models associations.

class user < activerecord::base   has_many :connections, :foreign_key => :sender   has_many :connections, :foreign_key => :receiver end  class connections < activerecord::base   belongs_to :user   has_many :archives end  class archive < activerecord::base   belongs_to :connection   belongs_to :archivable, :polymorphic => true end  class wink < activerecord::base   has_many :archives, :as => :archivable end  class game < activerecord::base   has_many :archives, :as => :archivable end  class message < activerecord::base   has_many :archives, :as => :archivable end 

do see wrong or not doable rails?

thank guys.

i think want :

class connections   belongs_to :sender, :class_name => 'user', :foreign_key => 'sender_id'   belongs_to :receiver, :class_name => 'user', :foreign_key => 'receiver_id'  end  class user   has_many :sended_connections, :class_name => 'connection', :as => :sender   has_many :received_connections, :class_name => 'connection', :as => :receiver end 

important : don't declare 2 times has_many :connections same name !


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -