the current Ecto documentation http://hexdocs.pm/ecto/Ecto.Schema.html only explains how to build a belongs_to
type of polymorphic association, when the polymorphic Comment
can belong to both Task
and Post
. But what about opposite direction?
For example there is a Listing
which can have a one of the four types of properties: Room
, Apartment
, Vila
or Office
.
Considering a one-to-one relationship, given the example above it would mean that there should be rooms_listings
, apartments_listings
, vila_listings
and office_listings
, which is impossible, because that will lead to the duplication of all of the other tables associated with listings
.
The question is how to model this kind of relationship?