Ecto.Associations.HasMany.Proxy
A has_many association.
Create
A new struct of the associated model can be created with struct/2. The
created struct will have its foreign key set to the primary key of the parent
model.
defmodule Post do
use Ecto.Model
schema "posts" do
has_many :comments, Comment
end
end
post = put_primary_key(%Post{}, 42)
struct(post.comments, []) #=> %Comment{post_id: 42}
Reflection
Any association module will generate the __assoc__ function that can be
used for runtime introspection of the association.
__assoc__(:loaded, assoc)- Returns the loaded entities or:not_loaded;__assoc__(:loaded, value, assoc)- Sets the loaded entities;__assoc__(:target, assoc)- Returns the model where the association was defined;__assoc__(:name, assoc)- Returns the name of the association field on the model;__assoc__(:primary_key, assoc)- Returns the primary key (used when creating a model withnew/2);__assoc__(:primary_key, value, assoc)- Sets the primary key;__assoc__(:new, name, target)- Creates a new association with the given name and target;
Summary
| all(arg1) | Returns a list of the associated structs. Raises |
| loaded?(arg1) | Returns |