FatEcto v0.5.0 FatEcto.FatQuery.FatInclude View Source
Preload associated schemas based on the conditions passed in the query params.
Parameters
queryable
- Ecto Queryable that represents your schema name, table name or query.query_opts
- Include query options as a map
Examples
iex> query_opts = %{
...> "$select" => %{
...> "$fields" => ["location", "rating"],
...> "fat_rooms" => ["name", "floor"]
...> },
...> "$order" => %{"id" => "$desc"},
...> "$where" => %{"rating" => 4},
...> "$include" => %{
...> "fat_doctors" => %{
...> "$include" => %{"fat_patients" => %{}},
...> "$order" => %{"id" => "$desc"},
...> "$where" => %{"experience_years" => 3},
...> "$join" => "$right"
...> }
...> }
...> }
iex> Elixir.MyApp.Query.build!(FatEcto.FatHospital, query_opts)
#Ecto.Query<from f0 in FatEcto.FatHospital, right_join: f1 in assoc(f0, :fat_doctors), left_join: f2 in assoc(f1, :fat_patients), where: f0.rating == ^4 and ^true, where: f1.experience_years == ^3 and ^true, order_by: [desc: f1.id], order_by: [desc: f0.id], limit: ^34, offset: ^0, select: map(f0, [:location, :rating, {:fat_rooms, [:name, :floor]}]), preload: [[fat_doctors: [:fat_patients]]]>
Options
$include
- Include the assoicationdoctors
.$include: :fat_patients
- Include the assoicationpatients
which has association withdoctors
.$select
- Select the fields fromhospital
androoms
.$where
- Added the where attribute in the query.$order
- Sort the result based on the order attribute.$join
- Join thedoctors
table withhospital
.
Link to this section Summary
Functions
Preload associated schemas.
Link to this section Functions
Preload associated schemas.
Parameters
queryable
- Ecto Queryable that represents your schema name, table name or query.include_params
- Include query options as a map.model
-schema
name of the table.build_options
- Pass options related to otp_app.
Examples
iex> query_opts = %{
...> "$include" => %{
...> "fat_doctors" => %{
...> "$include" => %{"fat_patients" => %{}},
...> "$order" => %{"id" => "$desc"},
...> "$where" => %{"experience_years" => 3},
...> "$join" => "$right"
...> }
...> }
...> }
iex> Elixir.FatEcto.FatQuery.FatInclude.build_include(FatEcto.FatHospital, query_opts["$include"], FatEcto.FatHospital, [])
#Ecto.Query<from f0 in FatEcto.FatHospital, right_join: f1 in assoc(f0, :fat_doctors), left_join: f2 in assoc(f1, :fat_patients), where: f1.experience_years == ^3 and ^true, order_by: [desc: f1.id], limit: ^10, offset: ^0>