Giter Site home page Giter Site logo

Comments (2)

AndrewDryga avatar AndrewDryga commented on May 20, 2024

@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.

from ecto_mnesia.

Qqwy avatar Qqwy commented on May 20, 2024

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).

from ecto_mnesia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.