ecto Questions

2

Solved

I am trying to get a has_many :through relationship working in Ecto for a many-many relationship between a User model and Group model. The only information I was able to find online was related to...
Armenta asked 14/10, 2015 at 14:22

1

Solved

I'm trying to see if my current user's teams overlap with the passed in user's teams. I have something that works but I'm curious if it could me more efficient. Here is what I have: user_teams = f...
Viewless asked 24/7, 2018 at 13:30

1

Solved

I have this piece of code: case Timex.Timezone.get(data) do {:error, _} = error -> error data -> {:ok, data} end to put timezones that are saved in the database into a struct. Well w...
Sisile asked 10/7, 2018 at 18:33

2

Solved

I'm trying to build an Ecto query with a left join with optional extra conditions on the join. I'll try to describe it with the typical posts and comments example. Post has_many Comments Comment b...
Barragan asked 1/6, 2018 at 3:22

1

We are building an application where I am a driver and i travel from point A to point B.On my way i can find passengers who travel in the same route. We are using PostgreSQL with PostGIS extension...
Evert asked 14/9, 2017 at 12:46

1

Solved

I'm creating a simple API Rest using Phoenix. I am getting the following error when executing the command: mix ecto.migrate 22:25:14.197 [error] Postgrex.Protocol (#PID<0.193.0>) failed to c...
Logrolling asked 2/5, 2018 at 1:29

2

Solved

I'm trying to write a single changeset that will update a model and insert an association. I cannot find examples on how to use put_assoc/4 order = order |> Proj.Order.changeset(%{state: "err...
Maricruzmaridel asked 19/2, 2016 at 21:8

2

Solved

I am making an API only Phoenix app. I come from a Ruby on Rails background, so bear with me. Say I have a User model with email, password, password_hash, and role fields. I need to restrict the ...
Sac asked 9/10, 2016 at 0:39

1

Solved

The recommended way to handle polymorphic associations in Phoenix seems to be adding an intermediate schema that contains the references to the other schemas: Inverse polymorphic with ecto https:...
Schoolbag asked 16/3, 2018 at 19:38

4

Solved

I created a phoenix project from the hello example using digital ocean. I entered the username and password from the etc/motd.tail file. I keep getting the error message below. I am a beginner and ...
Nash asked 4/3, 2016 at 0:35

1

Solved

I'm working on a phoenix 1.3 project (using the default postgres database) and I'm trying to add a string array column with a default value of a populated list. Here's the migration: defmodule Df...
Eatables asked 23/2, 2018 at 15:22

2

Problem I have a files table and there are many other tables that create a one-to-one association, e.g. users might have a avatar and posts might have photo. A possible solution A possible solution...
Tuner asked 19/9, 2015 at 15:49

1

Solved

Are there any ways to preload records by selecting another joined columns? # table structure # User 1---* Post 1---* PostTag *---1 Tag # extract definition of scheme scheme "posts" do ... has_m...
Miniver asked 1/2, 2018 at 7:7

1

Solved

So I'm a newbie in phoenix. I created a simple api in my phoenix project the problem is that i want to add another field in my todo.ex I want to add an author field in my todo.ex FROM defmodule To...
Patience asked 29/1, 2018 at 5:2

8

I have an upsert requirement, so I need to call a postgres stored procedure or use a common table expression. I also use the pgcrypto exgtension for passwords and would like to use postgres functio...
Cloth asked 3/1, 2015 at 2:40

2

Solved

I've got an Ecto migration where I'd like to modify some columns but also migrate some data. For example: import Ecto.Query defmodule MyApp.Repo.Migrations.AddStatus do alter table(:foo) do a...
Calumniation asked 22/1, 2018 at 12:24

0

Repo.insert(changeset) returns {:ok, struct}, but struct has no preloaded associations. Am I forced to select query to preload it's associations? Or can I avoid a useless query somehow?
Concent asked 19/1, 2018 at 22:4

3

Solved

Like other functions in elixir (as well as Ecto's own transactions), I want to pattern match to handle potential errors with Ecto queries. Like this: case Repo.get!(User, id) do {:ok, user} ->...
Eternalize asked 11/4, 2015 at 17:21

3

Solved

Let say I have a User model which has_many Post. I fetched a user: user = Repo.get(User, 1) and now I want to get all posts for this user. The only solution I found is to: posts = Repo.preload...
Resignation asked 6/10, 2016 at 13:0

2

Solved

I'm using Ecto to request data from the database, and I've used the following code to preload the cats filtered by price_discount. Item |> join(:inner, [i], c in Cat, c.food_category_id == i.id...
Gastrology asked 28/11, 2017 at 15:54

1

Solved

I know the difference between the two; assoc_constraint uses the ecto schema to validate the foreign key constraint, foreign_key_constraint uses the db. Why would you ever use assoc_constraint in ...
Atmometer asked 31/10, 2017 at 15:26

1

I created a fork of ecto repository to extend Ecto.Changeset module with the ability to add warnings to the changeset. I wanted to have an add_warnings/4 function which adds a warning to the change...

1

Solved

Is there any way to dynamically create and use models in Phoenix? I have an application that stores metadata about clients' tables: they set a handful of fields (column names and types) and then se...
Castro asked 20/10, 2017 at 16:19

2

Solved

# mix.exs defp deps do [{:phoenix, "~> 1.1.4"}, {:postgrex, ">= 0.0.0"}, {:phoenix_ecto, "~> 3.0.0-rc"}, {:gettext, "~> 0.9"}, ... ] end The installed ecto version is "2.0.0-r...
Corpulent asked 31/5, 2016 at 4:54

6

Solved

With PostgreSQL, we can do something like this: CREATE TYPE order_status AS ENUM ('placed','shipping','delivered') From Ecto's official doc, there is no native type to map the Postgres' enumerat...
Martres asked 6/2, 2016 at 20:5

© 2022 - 2024 — McMap. All rights reserved.