Top "Polymorphic-associations" questions

Polymorphic association is a term used in discussions of Object-Relational Mapping with respect to the problem of representing in the relational database domain, a relationship from one class to multiple classes.

how to generate migration to make references polymorphic

I have a Products table and want to add a column: t.references :imageable, :polymorphic => true I was trying …

ruby-on-rails polymorphic-associations rails-migrations
Possible to do a MySQL foreign key to one of two possible tables?

Well here's my problem I have three tables; regions, countries, states. Countries can be inside of regions, states can be …

mysql polymorphic-associations
ActiveRecord - querying polymorphic associations

I am using polymorphic associations to track Comments in my project. All very straight forward stuff. The problem I have …

ruby-on-rails ruby activerecord polymorphic-associations
Why can you not have a foreign key in a polymorphic association?

Why can you not have a foreign key in a polymorphic association, such as the one represented below as a …

ruby-on-rails database foreign-key-relationship polymorphic-associations
Rails Polymorphic Association with multiple associations on the same model

My question is essentially the same as this one: Polymorphic Association with multiple associations on the same model However, the …

ruby-on-rails polymorphic-associations
Rails polymorphic has_many :through

I'm pulling some data from an external API and would like to cache the results locally. I have a class …

ruby-on-rails activerecord polymorphic-associations
How to use constant in the ON condition in Yii2 hasMany relation

I try to create a polymorphic association, what is common in Rails but unfortunately not in Yii2. As part of …

yii2 has-many polymorphic-associations relation
accepts_nested_attributes_for with belongs_to polymorphic

I would like set up a polymorphic relation with accepts_nested_attributes_for. Here is the code: class Contact <…

ruby-on-rails ruby polymorphic-associations nested-attributes
MySQL - Conditional Foreign Key Constraints

I have following comments table in my app: comments -------- id INT foreign_id INT model TEXT comment_text TEXT ... …

mysql sql database-design foreign-keys polymorphic-associations
Foreign key to one of many tables?

The usual way of setting a foreign key constraint is to choose which table the foreign key will point to. …

mysql database postgresql polymorphic-associations