Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to assign multiple has_many ":as" polymorphic relation on same field?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. CORails polymorphic associations typically are different than you're writing. To do your Sender or Receiver, you would typically create a class that works for both such as: class Postcard < ActiveRecord::Base belongs_to :mailable, :polymorphic => true end class Sender < ActiveRecord::Base has_many :postcards, :as => :mailable end class Receiver < ActiveRecord::Base has_many :postcards, :as => :mailable end
      singulars
    2. CO@joelparkerhenderson thanks for your reply. Unfortunately I have multiple User types for example: Doctor < User and Patient < User. Being each User either a Sender or a Receiver I think final code would be unreadable/unusable. Am I right?
      singulars
    3. CODepends on how you set it up. In general Rails STI (Single Table Inheritance) works pretty well for classes with large overlap IMHO; a more advanced way to set up your classes is by changing from inheritance to associations (so a Doctor has_one User) or to DCI (Data Context Integration) which makes Doctor and Patient two "roles" that a user can mix in at runtime. There's also a way to do double-sided polymorphic joins-- try searching for an older gem by Evan Weaver that does it, and see if it's maintained or has a successor.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload