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.

Source

Summary

all(arg1)

Returns a list of the associated structs. Raises AssociationNotLoadedError if the association is not loaded

loaded?(arg1)

Returns true if the association is loaded

Functions

all(arg1)

Returns a list of the associated structs. Raises AssociationNotLoadedError if the association is not loaded.

Source
loaded?(arg1)

Returns true if the association is loaded.

Source