bodhilogic

bodhilogic

Problem with Ecto prefix: usage

I am attempting to use the prefix: attribute in my queries so that I can control which mySQL database I am reading/writing from.

When I attempt a Repo.get_by() call, Elixir moans that t.prefix doesn’t exist (or something similar to that) - Ecto thinks the prefix: attribute is a table field (column) and not the indication of which database to query.

Repo.get_by(Ticket, ticket: ticket_params[:ticket], prefix: "other_db")

The prefix: attribute seems(?) to work okay with other query types like Repo.insert!(prefix: "other_db") or Repo.get!(Ticket, id, prefix: "other_db") or Repo.all(prefix: "other_db"), etc.

What am I doing wrong?

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

You need to wrap the parameters you’re getting by in a list instead of using the last arg syntax sugar:

Repo.get_by(Ticket, [ticket: ticket_params[:ticket]], prefix: "other_db")

What you have is being interpreted as:

Repo.get_by(Ticket, [ticket: ticket_params[:ticket], prefix: "other_db"])

Also Liked

fmcgeough

fmcgeough

ah..right.. so the 2nd param is a Keyword. so prefix: “other_db” is just another element in the 2nd param Keyword List.

bodhilogic

bodhilogic

I created another server and in the process was able to run my changed code.

Bracketing the query parameters as suggested by benwilson512 worked a treat!!

Thanks.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

We're in Beta

About us Mission Statement