Relations
One to One
schema "organization_subscriptions" do
belongs_to :organization, ReactPhoenix.Organizations.Organization, type: :string
# subscriptions has organization_id schema "organizations" do
has_one :subscription, ReactPhoenix.Organizations.Subscription
#nothing in table organizationsUsage
# Can Preload the belongs_to post on the comment
[comment] = Repo.all(from(c in Comment, where: c.id == 42, preload: :post))
comment.post #=> %Post{...}
#Or the post
[post] = Repo.all(from(p in Post, where: p.id == 42, preload: :comments))
post.comments #=> [%Comment{...}, ...]Updating from parent
Create/Update Relations
Example Schema
Last updated