Skip to content

Instantly share code, notes, and snippets.

@ctrlShiftBryan
Created June 12, 2016 14:14
Show Gist options
  • Select an option

  • Save ctrlShiftBryan/011f792a4fdde4164bf161e6e241d43b to your computer and use it in GitHub Desktop.

Select an option

Save ctrlShiftBryan/011f792a4fdde4164bf161e6e241d43b to your computer and use it in GitHub Desktop.
defmodule Image do
@moduledoc false
use Ecto.Model
@primary_key {:Id, :binary_id, autogenerate: false}
schema "Images" do
field :name
field :extension
field :path
end
end
defmodule Section do
@moduledoc false
use Ecto.Model
@primary_key {:id, :binary_id, autogenerate: false}
schema "Sections" do
field :name
field :number, :integer
field :systemonly, :boolean
has_many :image_sections, ImageSection, foreign_key: :sectionid
end
end
defmodule ImageSection do
@moduledoc false
use Ecto.Model
@primary_key false
schema "ImageSections" do
field :imageid, :binary_id, primary_key: true
field :sectionid, :binary_id, primary_key: true
field :Previousimageid, :binary_id
has_one :image, Image, references: :imageid, foreign_key: :id
end
end
def query5 do
query = from i in Section,
select: i, limit: 100, preload: :image_sections
Repo.all(query)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment