ecto Questions

1

I have an Elixir struct with an embedded struct, following the instructions from José Valim himself: http://blog.plataformatec.com.br/2015/08/working-with-ecto-associations-and-embeds/ defmodule M...
Cruiser asked 21/12, 2020 at 1:57

1

Solved

When Ecto queries get more complex and require clauses like CASE...WHEN...ELSE...END, we tend to depend on Ecto's fragment to solve it. e.g. query = from t in <Model>, select: fragment("...
Roue asked 13/5, 2021 at 14:33

3

Solved

I have two tables. A table of topics which has_many tweets. My table of tweets belongs_to a topic. Topic Schema: defmodule Sentiment.Topic do use Sentiment.Web, :model schema "topics" do fi...
Water asked 14/7, 2017 at 19:10

6

Solved

I have this original migration that have already been run and sent upstream: create table(:videos) do add :url, :string add :title, :string add :description, :text add :user_id, references(:us...
Consideration asked 1/2, 2016 at 22:47

2

I'm trying to populate a field :params (from a Model/Schema) which is a map. I've got a working form_for and I'd like to populate this :params map through checkboxes so that when the form is submit...
Pee asked 20/1, 2016 at 12:46

6

Solved

I'm trying to format a Postgres date representation into a ISO 8601 string. I'm assuming that there is a Postgres function that can do it, but I found the documentation short on examples. My quer...
Eyelash asked 8/8, 2016 at 16:14

1

I'm working through the guide about Phoenix contexts (https://hexdocs.pm/phoenix/contexts.html#thinking-about-design), at the part where you run mix ecto.gen.migration add_author_id_to_pages and t...
Metathesize asked 20/1, 2021 at 7:3

2

Solved

I have an SQL query like : SELECT SUM(CASE WHEN <table_name>.status = '2' THEN 1 ELSE 0 END) FROM <table name>. I want to write the corresponding Ecto Query for the above. Something l...
Frey asked 1/12, 2015 at 13:46

4

Solved

in the Phoenix application, I have a function that takes two maps, and creates two entries in the database via Ecto.Changeset. def create_user_with_data(user_attrs, data_attrs) do name = cond do ...
Haroldson asked 17/11, 2017 at 16:6

1

I have problems with consolidation of protocol implementation in my Elixir project. To be more specific I use Ecto and some simple project called Gold (doesn't matter much atm). The problem is, bot...
Titograd asked 5/7, 2016 at 21:30

2

Solved

Is it possible to fetch 10 random records from database using only pure Ecto queries, and not on application side? For example, I'm don't want to get all records from the database and then take ran...
Katleen asked 6/11, 2018 at 4:13

2

This has been asked here How to add timestamps to an existing table with Ecto's timestamps?, however the accepted solution means that every new entry will have the same default time. I would wa...
Panayiotis asked 27/3, 2018 at 14:51

2

Solved

Is there a way to figure out if struct is persisted or not? I started digging source for Ecto's insert_or_update but with no luck as it hits some private method. I want to accoplish something like ...
Claque asked 25/3, 2017 at 4:53

4

Solved

I want to perform a query like the following one: SELECT id, name FROM mytable ORDER BY FIELD(name, 'B', 'A', 'D', 'E', 'C') FIELD is a MySQL specific function, and 'B', 'A', 'D', 'E', 'C' are v...
Anissaanita asked 23/12, 2016 at 12:58

2

Solved

I'm wanting to store a tree structure in Postgres, and I'm hoping to embed an arbitrary Elixir struct on each node of the tree, something like this: defmodule Node do use Ecto.Schema schema "no...
Downes asked 23/10, 2016 at 21:52

3

Solved

Doing upsert is common in my app and I want to implement the cleanest and simple way to implement upsert. Should I use fragments to implement native sql upsert? Any idiomatic ecto way to do upser...
Whirlwind asked 8/6, 2016 at 7:33

2

Solved

Let's say I have two models, Post and Comment and the comment model can be 1 out of 2 types, normal and fancy which is defined by the column type in the comments table. Now I want to add 2 associ...
Bisitun asked 23/10, 2015 at 3:18

4

Solved

I have an Ecto.Query and a Repo, such that I can call Repo.all(query) and get results. However, the results are not what I expect. How can I see the raw SQL the Repo will generate from the Ecto.Qu...
Danas asked 21/4, 2016 at 13:23

1

Solved

Would like to use DateTime in Ecto schemas and migrations, instead of the default NaiveDateTime, and also timestamptz in PostgreSQL, instead of the default timestamp (aka. timestamp without time zo...
Luralurch asked 2/10, 2019 at 17:40

4

Solved

This function: defp entries(query, page_number, page_size) do offset = page_size * (page_number - 1) query |> limit([_], ^page_size) # error |> offset([_], ^offset) |> Repo.all end ...
Egger asked 9/8, 2016 at 6:58

1

Solved

I know how I can use dynamic fields and values into Ecto query, for example: field = :age value = 20 Ecto.Query.where(App.User, [x], field(x, ^field) < ^value) But, it is possible to define t...
Shahjahanpur asked 6/9, 2019 at 16:48

5

Solved

Whatever in iex> or using mix run -e "My.code" when I run the mix project using ecto, the Ecto's Debugging Mechanism display a bunch of SQLs like below 16:42:12.870 [debug] SELECT a0.`id` FROM...
Sands asked 18/5, 2015 at 7:55

1

Solved

The Ecto documentation describes the options available to references/2, but does not document what those options do. The options available are: :nothing :delete_all :nilify_all :restrict What d...
Wenda asked 6/8, 2019 at 22:39

2

Solved

Although I am passing the query to repository inspired by this answer like this: teams_users = Repo.all (from(t in Team, where: t.owner_id == ^user_id)) |> Enum.each( &team_users/1 ) def...
Dorm asked 31/5, 2016 at 14:7

2

Solved

In my Phoenix JSON API I am getting an Ecto NoResultsError when I request an object that doesn't exist in the database. I want my JSON API to return a null along with a 404 error. How would I do ...
Chacma asked 6/12, 2015 at 1:27

© 2022 - 2024 — McMap. All rights reserved.