ecto Questions

2

Solved

I'm trying to return some JSON Data in one of my API Calls in Phoenix. I'm fetching all records of Subject and sending them but Ecto returns some extra fields that I do not want. What can I do to:...
Concretion asked 6/7, 2015 at 20:35

4

Solved

How can I do conditional validation for OR logic, where we check to see if 1 of the 2 values is present or both values are present. So, for example, if I want to check to make sure that the email ...
Sandhurst asked 13/2, 2017 at 19:54

4

Solved

I have a small pipeline in elixir, it's about changing ecto model state: model |> cast(params, ~w(something), ~w()) |> conditional |> Repo.update The problem is that I have conditional ...
Irreligion asked 7/5, 2016 at 4:33

3

Solved

Let's describe the problem: I created a new phoenix app with mix phx.new I configured a database connection within {dev, test}.exs (I'm mapping an existing database) I created a context using mix ...
Shagbark asked 11/11, 2020 at 11:15

2

Solved

Sometimes I get (Ecto.StaleEntryError) attempted to update a stale struct when trying to update record. I haven't found any recipe to avoid this in Ecto's docs, so what should I do to avoid this? ...
Amelioration asked 16/4, 2017 at 16:23

3

Solved

Is there a built-in way in Ecto to remove trailing and leading whitespaces of fields in Ecto.Changeset when calling changeset/2 before inserting it to the database? At the moment, I am adding tw...
Congregational asked 10/4, 2018 at 9:27

3

Solved

A few days ago I started using Elixir and the Phoenix Framework (v 0.12.0) with a Postgres database. I'm trying to create a table which has a UUID primary key, which I prefer over the sequential de...
Vins asked 2/5, 2015 at 15:19

6

Solved

Is there any way to do the inverse to preload? %Post{ comments: [] } posts = Repo.all(Post) |> Repo.unload(:comments) %Post{ comments: #Ecto.Association.NotLoaded<association :comments i...
Jubilate asked 24/4, 2018 at 8:15

1

I'm working on the complex registration form. My users will have their profiles with contact info and collections of items. My schemas (User, Profile, Phones, Collections, Items) look like this: d...
Papaya asked 25/6, 2017 at 9:7

2

How would I go about using the result of a recursive CTE in a query I plan to run with Ecto? For example let's say I have a table, nodes, structured as so: -- nodes table example -- id parent_id ...

3

I started getting the following error when trying to insert a new room ** (Ecto.ConstraintError) constraint error when attempting to insert struct: * unique: rooms_pkey If you would like to con...
Hipolitohipp asked 28/9, 2017 at 18:16

3

Solved

I want to create a SQL using the keywork 'between' in Elixir Ecto. I know how to create a sql using like where: like(t.descript, ^some_description) But when I try to do it in the same way as lik...
Appaloosa asked 19/5, 2015 at 7:24

2

Solved

What I'm trying to do is passing an empty string as the value of a field, and validating it to check if not nil. Problem is that validate_required raise error on both nil and blank values. How to m...
Tasha asked 18/8, 2017 at 10:16

4

I'm running a build on a Buddy continuous integration server and it is bailing out with errors when executing mix test when it gets to the postgrex/ecto portion: ==> postgrex Compiling 61 file...
Till asked 4/2, 2017 at 9:12

3

Solved

I am trying to look for all Users that don't have a certain string element in their match_history field. I took a guess with this: matched_user = User |> where([u], ^device_id not in u.match_hi...
Comenius asked 6/12, 2016 at 21:32

2

Solved

It is a bit of a joke that I have to ask this but it is really not clear what the best way is. So this might turn into a little rant. But I have the fealing that Elixir lacks seriously here. I fi...
Outwardly asked 25/10, 2016 at 15:12

3

Solved

When running an Ecto test with mix test ..., the SQL executed is not shown. As far as I can tell, it is not logged to any file, either. How can I see it? (I am using Ecto as part of a Phoenix appli...
Hurlbut asked 14/2, 2017 at 21:0

1

I need to test expiration and for that, I need to assign inserted_at field, however when I do: insert_registration(Map.put(attrs, :inserted_at, Ecto.DateTime.cast("2016-03-11 00:00:00")))...
Isentropic asked 24/5, 2016 at 11:39

2

Solved

I'm running a search feature on three tables in my Phoenix app, and I want to join them using something like SQL's UNION operator. I have three tables: mix phx.gen.json Accounts User users handle...
Evansville asked 13/10, 2017 at 0:13

2

I created a custom function in Postgresql that checks data before insert or update and raises error if something goes wrong. CREATE FUNCTION custom_check() RETURNS TRIGGER AS $$ BEGIN IF <SOM...
Adriaadriaens asked 2/11, 2018 at 16:14

4

Solved

I'm just learning Phoenix and Elixir and I'm coming from Ruby/Rails where I work in the REPL using pry to inspect my database and application state. I'm trying to figure out how to interact with m...
Chesty asked 26/10, 2015 at 15:23

5

Solved

How to convert the time in milliseconds to Ecto.DateTime? The time in milliseconds is the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
Ignazio asked 19/6, 2016 at 9:19

2

Solved

I am trying to learn the Phoenix's Form system with including the Ecto.Model's but i have encountered a problem that i can't pass. I have created a form: <div class="jumbotron"> <%= form...
Wobble asked 29/11, 2015 at 12:54

1

Solved

I'm unable to successfully run an Ecto migration to drop a unique index that, when originally created, had been provided with a :name attribute (so that the default index name was not used). Howeve...
Footsie asked 10/6, 2021 at 18:19

1

I have written the following test. test "list_users/1 returns all users in a tenant", %{tenant: tenant} do user = insert(:user, tenant: tenant) user_2 = insert(:user, tenant: tenant) assert Ac...
Raptor asked 14/6, 2017 at 15:17

© 2022 - 2024 — McMap. All rights reserved.