Questions tagged [ecto]

Ecto is a domain specific language for writing queries and interacting with databases in Elixir.

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

How to filter preloads on an Ecto query (postgres), on: isn't working as expected

from(t in Task, join: tf in TaskFactory, on: t.task_factory_id == tf.id, left_join: ts in TaskSkip, # Expect the `and is_nil(ts.deleted_at)` to not return deleted ...
bezzoon's user avatar
  • 1,819
0 votes
0 answers
26 views

Testing raw sql queries in elixir

I'm trying to unit test a raw sql query but not getting any results. My test does a number of inserts like: Repo.insert!(%Inquiry{<fields>}) My inquiries select part does truncating of a ...
Brad Pardee's user avatar
0 votes
2 answers
53 views

Adding a Limit Option to Ecto's Repo.preload in Elixir

I have a function in Elixir using Ecto that preloads associations for a given entity. The current implementation looks like this: @spec get(integer() | String.t(), list()) :: t() | nil def get(id, ...
IvonaK's user avatar
  • 161
1 vote
0 answers
22 views

How to set the SSL options when connecting to Heroku in Phoenix framework?

I recently upgraded Phoenix to the newest version(1.7.7) and Ecto was also upgraded to 3.10.3. Before upgrading, when connecting to Heroku pg, i just set SSL: true and the connection is OK: config :...
tomwang1013's user avatar
  • 1,389
0 votes
1 answer
61 views

Validation errors not shown in Phoenix LiveView form

I am using Elixir with Phoenix. I have a form with a text input which should only allow a maximum text of 255 characters. However, the error is not shown I could not figure out why it does not show ...
Greeneco's user avatar
  • 701
0 votes
1 answer
50 views

In elixir, how put_assoc is supposed to be used?

For a project, I need to create a little appilcation in Elxir, Phoenix with Ecto as ORM. I'm a complete beginner on this technologies and I'm stuck with a saving problem on a many-to-many association. ...
Lucas's user avatar
  • 21
0 votes
1 answer
36 views

How guard nil in math function if it drops with bad argument in arithmetic expression

Trying figure out, while generating GQL schema, why if :float data in source var square_plot exists (say 50), there is no ERR but if it is NIL the code generates error while i converting value so sqft ...
Dan's user avatar
  • 5
0 votes
1 answer
37 views

Is it possible to generate a query clause that combines data from multiple db columns using Ecto.Query?

I have a simple Postgres table that stores first_name and last_name for Person records. Let's say it contains the following example data: first_name last_name John Smith Jane Doe Bob Smith Mark ...
Jethro Cao's user avatar
  • 1,010
0 votes
0 answers
42 views

In Elixir/Phoenix/Ecto, how can I create a fixture with modified timestamp values for testing?

I want to be able to create a test data with custom inserted_at value for testing. Is this possible? Ideally it should be flexible so I can adjust the date to the test I want to write. I've search the ...
Jonathan Lightbringer's user avatar
0 votes
1 answer
37 views

closest string match in Elixir or Ecto

I am trying to compare 2 strings which are basically addresses. I was trying to use jaro_distance iex(1)> String.jaro_distance("4420 West Main Street", "EUTECTIC CORPORATION QA ...
Junaid Farooq's user avatar
1 vote
2 answers
60 views

Check a complex unique constraint with Ecto

In my Ecto schema, I have a User who has_many Items. An item has a boolean field active: User module: schema "users" do field :name, :string has_many :items, Item end Item ...
martasd's user avatar
  • 125
0 votes
2 answers
34 views

Ecto CastError: value in `join` cannot be cast to type {:in, :string}

I had a list defined like so: flags = ['flag_a', 'flag_b'] And a query set up something like this: from(u in User, left_join: f in Flags, on: f.account_id == u.account_id and f.name in ^@...
Hannele's user avatar
  • 9,426
2 votes
0 answers
27 views

Insert exactly one sequence-breaking record?

This is at the intersection of Ecto & Postgres. I can't figure out how to create a one-off record into a normal table with a sequential id column using Ecto. I have a standard (?) ecto schema ...
Andrew Cunningham's user avatar
0 votes
2 answers
166 views

How to create a simple association between two tables in Phoenix and submit the data

I am learning how to configure a belong_to / has_many relationship between two tables. I have the configuration complete but I don't know the syntax to invoke it. I want to take a pre-existing Table ...
William's user avatar
  • 4,240
0 votes
0 answers
49 views

How do I extend Ecto.Repo to broadcast changes to pubsub?

I'm trying to get my app's Repo to broadcast inserts on a phoenix channel, but I'm not sure about the right way to extend Ecto.Repo. I've tried this, but I'm getting compilation, and it doesn't like ...
cjm2671's user avatar
  • 18.5k
0 votes
1 answer
41 views

Is there a replacement for ActiveRecord `source` in ecto?

Please help me in finding the elixir/ecto option for :source option of has_one/has_many :through association of ActiveRecord. Here is my problem, I have the following schemas: User, Event, ...
Linda Kadz's user avatar
0 votes
1 answer
29 views

How use st_buffer function in ecto query in postgis?

I try do query in postgis like this from(r in Region, select: count(r.ogc_fid), where: st_intersects( r.region_geometry, fragment( ...
Максим Барулин's user avatar
0 votes
0 answers
31 views

How to store/represent dynamic "sub-groups" created with user-provided filters on a parent `contacts` table?

We have a contacts table with the following structure: id name email status last_appointment_at campaign_id ... 1 John Smith [email protected] HOT 2023-01-01 1 ... 2 Jane Doe [email protected] COLD ...
Ian Mac's user avatar
  • 33
0 votes
1 answer
166 views

Ecto create unique index with nulls

I'm trying to create a unique index with an ecto migration for a PostgresDB. def change do create table(:categories) do add(:name, :string) add(:parent_id, references(:categories), null: ...
spinners's user avatar
  • 2,499
0 votes
1 answer
63 views

Getting `null value in column "id" of relation table_name` when I try to save something to the database in Phoenix

Every time I try to run a Repo.insert with this particular table, I get an error about the id being null (null value in column "id" of relation table_name), but the id isn't supposed to be ...
neurodynamic's user avatar
  • 4,336
1 vote
1 answer
634 views

Hi, I had created Elixir project with phoenix framework. there is yaml file when i build that file i get this error

== Compilation error in file lib/ecto/query.ex == ** (Kernel.TypespecError) lib/ecto/query.ex:428: type dynamic/0 is a built-in type and it cannot be redefined (elixir 1.15.0) lib/kernel/typespec....
Sanket Zeple's user avatar
0 votes
1 answer
69 views

How to model a self-referencing has_many relationship in ecto

I want to model a has_many children relationship in Ecto. I am wondering if I need a separate table to store this relationship. Or is it enough to store the relationship between a todo and its parent. ...
bezzoon's user avatar
  • 1,819
1 vote
0 answers
101 views

How could I successfully implement an upsert function with Ecto?

I'm trying to implement an upsert/2 function to my entities on a Phoenix context. For example I'll show only one schema. Firstly, here's the migration for the tag table: defmodule Pescarte.Repo....
Zoey's user avatar
  • 474
0 votes
0 answers
38 views

Ecto-Waffle Multiple Images, Different Transformations

Wanted Behavior: Given three images with different transformations applied uniquely to each image, use waffle and ecto-waffle to apply these changes uniquely in my changeset. I would like something ...
mastari's user avatar
  • 89
0 votes
1 answer
36 views

Count number of items on has_many relationship, including entries with no records

I have two models in my Phoenix app: School and User. A school can have many users. This relationship is defined by the SchoolUser model. I want to list all schools and count how many students each ...
Will's user avatar
  • 2,553
0 votes
1 answer
77 views

How to Convert updated_at to Conventional 12 Hour Format with My Time Zone?

In Phoenix, Ecto gives me a timestamp named updated_at, and it presents time in this way: 2023-05-31T18:44:44 I want to format it to 12 hour time and convert it to my time zone. I can format it to a ...
William's user avatar
  • 4,240
0 votes
1 answer
51 views

Waffle-Ecto Changeset Field Image Resize | Phoenix/Elixir

I am trying to apply ImageMagick transformations to a Waffle-Ecto image in a @changeset before I upload to my AWS bucket. Here is my schema defmodule App.Images.Image do use Ecto.Schema import ...
mastari's user avatar
  • 89
0 votes
1 answer
138 views

Deprecated Ecto.DateTime casting with newer version of Elixir

I have an older version of Elixir code which use Ecto.DateTime.cast(). However since the release of Ecto 3.x, Ecto.DateTime is deprecated. I have the following code and I'm wondering how to convert to ...
tmariaz's user avatar
  • 57
0 votes
0 answers
64 views

Ecto ConnectionError timeout after Postgres DB Partitioning Implementation

Recently we updated the database structure of our multi-tenant Phoenix app to implement declarative partitioning for several tables (using PostgreSQL 14 on an AWS RDS instance). Following Ecto's ...
Cole Meurer's user avatar
1 vote
1 answer
120 views

Ecto Multi.run returns clause matching anonymous fn/2 error

I have the following Ecto.Multi but it throws an error. I'm running on Phoenix 1.6.15 with Ecto 3.9.2. Not sure what I'm doing wrong... Code: result = Multi.new() |> Multi.run(:...
tmariaz's user avatar
  • 57
2 votes
2 answers
1k views

How to check whether a string is a valid UUID?

I'm using Phoenix and Ecto. In a model I have a UUID field. In some cases I'll need to check whether a string that comes from a user is a proper UUID. How to do it? I've checked out https://hexdocs.pm/...
Marco C. Stewart's user avatar
0 votes
1 answer
51 views

How to use this specific Repo function with web socket actions

I have put together a small web socket todo app based on reading on-line tutorials and the like. I have a working app that submits data to the database and retrieves data, all with web socket ...
William's user avatar
  • 4,240
-1 votes
1 answer
171 views

Phoenix LiveView basic sorting of data for render

I want to sort this data by name. I am unsure how to do it via the view or from Repo. I know there is a Enum.sort() module, but I am not sure how to integrate it with the view code. I've played with ...
William's user avatar
  • 4,240
1 vote
1 answer
119 views

How to query for dates or date range

I am trying to make possible to filter products by their insertion date. It can be a single date as a from/to date of filtering or a range from starting to ending date from the form. I'm unsure if I'm ...
Kacper Wielki's user avatar
0 votes
1 answer
145 views

Elixir - Phoenix / Ecto - using multiple foreign keys to setup a has_many relationship

I have 4 modules, a Studio, a Studio Type, a Site, and a Config. The setup is that each site has many studios and configs, and so does each studio type. This means both studios and configs have a site ...
Mark's user avatar
  • 6,192
0 votes
1 answer
229 views

Dynamic Elixir Ecto Query

I have a list of fields, and I want to take that list and dynamically create an Ecto query from it. I think I can use Enum.reduce, but I'm not sure how to get the pieces to work together. Each field ...
Billbryson78's user avatar
0 votes
1 answer
81 views

Protocol Ecto.Queryable not implemented for Item of type List

Background I have an List of metadata items that has the following format: [%{id: "id1"}, %{id: "id2"}, %{id: "id3"}] I am trying to do a query using a join with this ...
Flame_Phoenix's user avatar
0 votes
0 answers
89 views

Elixir TDS with Trusted Connection

I am trying to connect MS-SQL from Elixir with tds. I do not have an userid-password, instead use windows auth. Is there a way to use the windows authentication to connect to a MS-SQL server. ...
Shishir Pandey's user avatar
0 votes
1 answer
118 views

How to append a string to a text column value in Postgres using Ecto

I have a postgres database with a dictionaries table containing a column called body. This column has a text datatype capable of holding strings of variable unlimited length. I am attempting to ...
vaer-k's user avatar
  • 11.1k
0 votes
1 answer
132 views

How to get the top X results of a given category using Ecto?

Background I have to queries that return a colossal amount of data on their own. I cannot use Repo.all as doing so would materialize these into memory, which would then quickly run out. So I am trying ...
Flame_Phoenix's user avatar
0 votes
1 answer
185 views

no function clause matching in Plug controller

My function does not match in the controller My router: scope "/api", AtmAppWeb do pipe_through :api get "/index", UserAtmController, :index get "/show", ...
Luis Marquez's user avatar
1 vote
1 answer
123 views

Is There a Way to Fetch a Type Attribute in An Ecto Query

I have an Ecto Schema with payments containing an amount field. That field's type is the Money.Ecto.Composite.Type from the ex_money package(v. 5.12.3). The query is: query = from( ...
paulrusu's user avatar
  • 117
0 votes
0 answers
76 views

Archiving a one-to-one relationship in Ecto

I have two models: Actor and Room. This is just a minimal example. # `Actor` Model defmodule MyApp.Actor use Ecto.Schema schema "actors" do field :actor_name, :string field :...
DaveIdito's user avatar
  • 1,546
0 votes
0 answers
38 views

How to get 0 if no such entry in a related table in Ecto? [duplicate]

I have three tables: location, product, and stock. In the stock table, the fields product_id, location_id, and quantity are present. However, when a location is created (or a product, for that matter),...
Basil's user avatar
  • 518
0 votes
0 answers
48 views

Ecto association on_replace action raises constraint error

I have a schema, which roughly resembles this: beehives has many(bees) bees has many(honeypots) honeypots belongs_to(bees) The beehives to bees relation has on_replace: :delete. Our app ...
nikc.org's user avatar
  • 16.6k
0 votes
1 answer
53 views

Not being able to preload has_many through associated data

My association are: defmodule Mp.Schema.User do use Ecto.Schema import Ecto.Changeset schema "users" do # ... has_many :user_gyms, UserGym, on_replace: :delete has_many :...
Rasna Shakya's user avatar
0 votes
0 answers
115 views

Connecting to MySQL with Ecto in Docker

I am in the process of Dockerizing my project, and the following is my docker-compose.yml: version: '3.8' services: server: image: server environment: DB_HOST: 0.0.0.0 ...
Basil's user avatar
  • 518
0 votes
1 answer
167 views

Using existing entries in an Ecto changeset function

I have a business_hours table (using MySQL) which contains the following fields: location_id (foreign key) starting_time (float [e.g. 17 = 5pm, 17.5 = 5:30pm]) ending_time (float) day (integer [0 = ...
Basil's user avatar
  • 518
1 vote
0 answers
385 views

In ecto migration is there a way to rename a table without updating the constraint references

I'm trying to change a non null column to a column that can be null. alter table(:members) do modify :email, :string, null: true end However as I'm using sqlite I'm getting: ALTER COLUMN not ...
user518184's user avatar
1 vote
1 answer
132 views

Querying jsonb field with @> through Postgrex adapter

I'm trying to query jsonb field via Postgrex adapter, however I receive errors I cannot understand. Notification schema def all_for(user_id, external_id) do from(n in __MODULE__, where: n.to == ^...
zhisme's user avatar
  • 2,482

1
2 3 4 5
36