How to query by 'embeds_many' item?

This is my order.ex

  schema "orders" do
    field :counts, :integer
    field :status, :string
    embeds_many :line_items, LineItem, on_replace: :delete
    field :user_id, :integer
    field :message_type, :string
    field :total, :decimal
    field :message, :string
    field :media_url, :string
    belongs_to :users, User, define_field: false

    timestamps()
  end

and line_item. ex

  embedded_schema do
    field :person_id, :integer
    field :name, :string
    field :phone_number, :string
  end

I want to find order by phone_number field in LineItem that embedded in order schema.
how do I make a query for this?

Not sure if there’s a more straightforward way, but you could use fragments, something like:

|> where([o], fragment("?->>‘phone_number’)", o.line_items) == ^phone_number)

In some cases you need to cast the result of the fragment as it’s returned as text, but in this case it should work as is.

edit: actually I don’t know if it works with embeds_many that works with embeds_one