New bee to Elixir Phoenix, coming from Java background, this framework amazed me till now
Am creating a Parent Child table and trying to Preload Child data along with parent following the instructions provided, but somehow in the API End point response I only see the parent object values
Parent Table Schema
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "parent" do
field :name, :string
has_many :child, Child
timestamps(type: :utc_datetime)
end
Child
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "child" do
field name, :string
belongs_to :parent, Parent
timestamps(type: :utc_datetime)
end
Migration Parent Table
def change do
create table(:parent, primary_key: false) do
add :id, :binary_id, primary_key: true
add :name, :string
timestamps(type: :utc_datetime)
end
end
Migration Child Table
def change do
create table(:child, primary_key: false) do
add :id, :binary_id, primary_key: true
add :name, :string
add :parent_id, references(:parent, on_delete: :nothing, type: :binary_id)
timestamps(type: :utc_datetime)
end
end
In the Repo file, here I was expecting child table data to be present along with Parent, but I dont see it
def list_parent do
Repo.all(Parent) |> Repo.preload(:child)
end
When I run the Query Interactively iex -S mix
, I can see the Parent and Child records populating, I tried all the options from google search, but still cant able to figure it out
Thanks Everyone