Hello,
I have 2 tables.
connection.ex
schema "connections" do
field :comment, :string
belongs_to :owner, Mdbms.Owner, foreign_key: :owner_id
timestamps()
end
def test(connection) do
from c in connection,
left_join: owner in assoc(c, :owner)
end
connections migration
def change do
create table(:connections) do
add :owner_id, references(:owners, on_delete: :nothing)
add :comment, :string
timestamps()
end
create index(:connections, [:owner_id])
create unique_index(:connections, [:id])
end
owner.ex
schema "owners" do
field :first_name, :string
field :last_name, :string
has_one :connections, Mdbms.Connection
timestamps()
end
In my page_controller.ex I have
def index(conn, _params) do
connections = Connection
|> Connection.test
|> Repo.all
render(conn, "index.html", connections: connections)
end
I want to display in my template records both from connection table and owner table.
There’s code below which I’ve put in my page/index.html.eex but this way I can only display records from connection table and I have no idea how to display for instance “owners.first_name”.
<%= for connection <- @connections do %>
<%= connection.comment %>
<% end %>