Skip to content

Ecto.Schema.belongs_to/3 documentation: Polymorphic associations #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
toraritte opened this issue Jun 15, 2018 · 0 comments
Open

Ecto.Schema.belongs_to/3 documentation: Polymorphic associations #15

toraritte opened this issue Jun 15, 2018 · 0 comments

Comments

@toraritte
Copy link
Owner

toraritte commented Jun 15, 2018

DON'T CONFUSE WITH MANY-TO-MANY!

https://hexdocs.pm/ecto/Ecto.Schema.html#belongs_to/3-polymorphic-associations

In Ecto, we have three ways to solve this issue. The simplest is to define multiple fields in the Comment schema, one for each association:

* task_id
* post_id

Unless you have dozens of columns, this is simpler for the developer, more DB friendly and more efficient in all aspects.

Is my assumption correct that here schema is used interchangeably with the repo (i.e., the database schema)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant