Call a Schema in a query from another context

Hi,

I have to contexts: Registry and Analytic.

I would like to make a join in the Analytic context with some schema that belongs to the registry context.

defmodule Quant.Analytic do

  import Ecto.Query, warn: false
  alias Quant.Repo

  alias Quant.Analytic.Rnod

  defmodule RnodFrontEnd do
    defstruct [:id, :entry, :exit, :risk, :atr, :vwap, :shares]
  end

  def list_rnods_fe do
    Repo.all(from r in Rnod,
              inner_join: f in Quant.Repository.Fact, where: f.id == r.fact_id,
              select: %RnodFrontEnd{id: r.id, entry: r.entry, exit: r.exit, risk: r.risk, atr: f.atr, vwap: r.vwap, shares: r.shares},
              order_by: r.id)        
  end
end

But I keep getting the following error: module Quant.Repository.Fact is not available.

What should I do?

That means that Quant.Repository.Fact is not found, but you showed the module for Quant.Analytic, can you show the module of Quant.Repository.Fact? :slight_smile:

In your join then you wrote Quant.Repository.Fact

when I’d expect to read something like Quant.Registry.Fact

Is it a wrong naming in your question?

Yes, I think it was a typo, but the solution was that, thanks!