ecto Questions

1

Solved

I want to validate that ends_on is always later or the same date as starts_on. But my custom validation doesn't work. What is the correct way to write this validation? defmodule Example.Calendar.V...
Canto asked 18/9, 2017 at 14:12

2

I have an application which targets multiple databases, it's like an application that watch applications which make reports, mediate notifications, run tasks and stuffs, in a way that is impossible...
Dowager asked 22/8, 2016 at 2:13

2

Solved

I'm just starting with databases and queries (coming from front-end) and I would like to select the latest entry from the fields that contain a specific title, say Page1. I know I have two fields t...
Yearbook asked 18/9, 2015 at 13:35

1

Solved

I'm new to Elixir and Phoenix (6 months learning), I have a situation where I want to assign an Ecto model's field (not primary key or table ID) to BIGINT in MySql. I realize when you create an Ec...
Ellett asked 30/7, 2017 at 14:7

3

I am inserting a model A that contains a foreign key to another model B. defmodule MyApp.ModelA do use MyApp.Web, :model schema "model_a" do field :type, :string, null: false field :data, :st...
Stylite asked 10/8, 2016 at 15:22

1

Solved

In my phoenix project, I have a posts and tags schema linked through a join table schema "posts" do field :title, :string field :body, :string many_to_many :tags, App.Tag, join_through: App.Po...
Tannertannery asked 15/7, 2017 at 2:26

2

I am relying on Ecto to return an error when an insert fails a database level constraint. Is it possible to run different code depending on the error type returned by Ecto? case Repo.insert(chan...
Realm asked 14/7, 2017 at 16:22

1

Is there any way to used embeds_many in Ecto without having an id / primary_key field? My database depends on having a unique index on this field, and ecto automatically inserting keys breaks this...
Luddite asked 15/8, 2016 at 3:53

3

Solved

How to find posts in given List of ids? This isn't working: posts = Post |> where(id: [1, 2]) |> Repo.all Example in Rails: Post.where({ id: [1, 2]}) # SELECT * FROM posts WHERE id IN (1...
Dimenhydrinate asked 23/4, 2016 at 17:43

2

Solved

I have an Ecto schema that includes field :owned_by_id, :string. I declared the field a string because I need to support values like "abc123" as well as values like "123". The docs for cast/3 say:...
Pinion asked 15/11, 2016 at 15:24

1

Solved

I have the following schema. defmodule Message do use Ecto.Schema schema "messages" do belongs_to :user, FPL.Club, foreign_key: :user_to_id belongs_to :user, FPL.Club, foreign_key: :user_from...
Anschluss asked 5/5, 2017 at 19:47

1

Solved

In my Phoenix app, I'd like to run a get_by() Ecto query for a single record - however, one of the fields that I want to search on should evaluate to nil, but Phoenix/Ecto forbids using nil as a co...
Regalado asked 27/4, 2017 at 23:33

2

Solved

I just want do execute an Ecto query with an simple concatination of two or more columns. I think the following elixir pseudo code already shows what I try to do: customers = Customer.undeleted( ...
Shelley asked 24/4, 2017 at 16:21

2

Solved

I have a table applications with a foreign key user_id that's a Postgres uuid. I have in my web.ex: @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id My model is:...
Epiphyte asked 18/7, 2016 at 1:41

1

I'm getting rather confused about Ecto when it comes to adding a new association to an existing model. Let's say I have some discussion board where users can like a post, and I have the following m...
Phylloquinone asked 2/12, 2016 at 19:56

1

Solved

Let's say I have this for fetching all threads: Thread |> Thread.ordered |> Repo.all |> Repo.preload([:posts]) How could I provide an order_by clause for :posts? I can't seem to locate ...
Vladimar asked 10/4, 2017 at 18:14

1

Solved

I am working on statistics page of my app and trying to query data by date. To get the date range, I use Calendar.Date date_range = Date.days_after_until(start_date, end_date, true) |> Enum.t...
Ethical asked 8/4, 2017 at 10:21

2

Solved

This is a theoretical question but assume the data structure cannot change and that this is definitely how we want to do the query. This question is more to get a better understanding of how where ...
Niple asked 27/9, 2015 at 23:2

1

Solved

ERROR 22001 (string_data_right_truncation): value too long for type character varying(255) I understand (and assumed) that a string would be limited to a certain number of characters; however,...
Squire asked 16/3, 2017 at 0:49

1

Solved

If the record does not exist, I would expect this conditional to create it, but it does not.... nil is returned. case Repo.get_by(User, %{email: "[email protected]"}) do struct -> struc...
Tamikatamiko asked 14/3, 2017 at 0:57

2

Solved

Currently working on Phoenix project using Ecto + Postgres. When creating a comment, as comment belongs_to both User and Article, is there a way to build multiple associations to generate one chang...
Dianadiandra asked 13/3, 2017 at 1:22

2

I'm trying to test a belongs to association in Elixir. Say I have two models, a Product and a ProductType. Products belong to a product type. defmodule Store.Product do use Store.Web, :model ...
Grieg asked 26/11, 2015 at 0:33

2

Solved

Usually mix.test cleans the test database, but it is not working. It may be because I was playing around with making a users schema, but didn't want to use what I made so I got rid of it. I then ...
Bondholder asked 10/2, 2017 at 14:55

1

Solved

I have two models, Personand Pet, and I want a Personto be able to have many pets, but a Petto belong to only one person: defmodule MyApp.Person do use MyApp.Web, :model alias MyApp.Pet schem...
Hymnal asked 9/2, 2017 at 13:17

1

Solved

I have one date-time in Ecto.DateTime and the 2nd one in DateTime. How can I convert them to each other? Isn't there a easy way without external dependencies? There's nothing in the documentation. ...
Wahkuna asked 8/2, 2017 at 3:59

© 2022 - 2024 — McMap. All rights reserved.