Ecto.Associations.HasOne.Proxy

A has_one 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_one :permalink, Permalink
  end
end

post = put_primary_key(%Post{}, 42)
struct(post.permalink, []) #=> %Permalink{post_id: 42}

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