Ecto.Associations.BelongsTo.Proxy

A belongs_to association.

Create

A new struct of the associated model can be created with struct/2.

defmodule Comment do
  use Ecto.Model

  schema "comments" do
    belongs_to :post, Post
  end
end

comment = %Comment{} 
struct(comment.post, []) #=> %Post{}

Reflection

Any association module will generate the __assoc__ function that can be used for runtime introspection of the association.

Source

Summary

get(arg1)

Returns the associated struct. Raises AssociationNotLoadedError if the association is not loaded

loaded?(arg1)

Returns true if the association is loaded

Functions

get(arg1)

Returns the associated struct. Raises AssociationNotLoadedError if the association is not loaded.

Source
loaded?(arg1)

Returns true if the association is loaded.

Source