Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'preload' results in 'Complex :in queries is not supported' error #62

Open
Qqwy opened this issue Jun 11, 2018 · 2 comments
Open

'preload' results in 'Complex :in queries is not supported' error #62

Qqwy opened this issue Jun 11, 2018 · 2 comments

Comments

@Qqwy
Copy link
Contributor

Qqwy commented Jun 11, 2018

When using an Ecto.Query.preload(:relation_name) in a pipeline with a query, the following error is thrown:

Complex :in queries is not supported by the Mnesia adapter.

This error is not indicative of what is happening here, so:

a) we need a better error.
b) maybe it is possible to support this feature after all?

@AndrewDryga
Copy link
Member

@Qqwy can you contribute a test that reproduces it? We do support some :in queries, but they are emulated by nested :or's and don't work in all possible cases.

@Qqwy
Copy link
Contributor Author

Qqwy commented Jun 12, 2018

Of course! I am building a chat application, and this is what I am doing:

Schemas:

defmodule MyApp.Chat.User do
  use Ecto.Schema
  import Ecto.Changeset

  schema "users" do
    belongs_to :app, MyApp.Chat.App
    field :name, :string
    has_many :sent_messages, MyApp.Chat.Message

    timestamps()
  end
end
defmodule MyApp.Chat.Message do
  use Ecto.Schema
  import Ecto.Changeset

  schema "message" do
    belongs_to :sender, MyApp.Chat.User
    belongs_to :conversation, MyApp.Chat.Conversation
    field :content, :string

    timestamps()
  end
end

Migrations:

defmodule MyApp.Repo.Migrations.CreateUsers do
  use Ecto.Migration

  def change do
    create table(:users) do
      add :name, :string
      add :app_id, :integer #references("apps")

      timestamps()
    end
  end
end
defmodule MyApp.Repo.Migrations.CreateMessage do
  use Ecto.Migration

  def change do
    create table(:message) do
      add :sender_id, :integer # references("users")
      add :conversation_id, :integer # references("conversations")
      add :content, :string

      timestamps()
    end
  end
end

(For this example, the 'conversation' schema and 'apps' schema are not really important)

I then attempt the following query:

      from(MyApp.Chat.Message, where: [conversation_id: ^conversation_id], order_by: [desc: :inserted_at], limit: 10)
      |> preload(:sender)
      |> MyApp.Repo.all()

to fetch all Messages which should each contain there respective sender.
Executing this query fails with the error shown above (Complex :in queries is not supported by the Mnesia adapter.).


I am not entirely sure how to extract a test out of this, but hopefully it does give you some indication of what is going on. (I try to run Ecto.Query.preload on a field that is a belongs_to in my schema).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants