Accessing resources across apis

I have the following resource and api structure

resource : PyqRatta.Databank.Question
resource: PyqRatta.Databank.Quiz has_many PyqRatta.Databank.Question
api : PyqRatta.Databank[PyqRatta.Databank.Quiz, PyqRatta.Databank.Question] (list of resources in api)

and

resource : PyqRatta.QuizPractice.Response belongs_to PyqRatta.Databank.Question
api : PyqRatta.QuizPractice[PyqRatta.QuizPractice.Response] (list of resources in api)

now, in response.ex


    relationships do
        belongs_to :question, PyqRatta.Databank.Question,
          attribute_writable?: true,
          attribute_type: :integer,
          allow_nil?: false
    end

I am getting error. App Name is PyqRatta

* (EXIT from #PID<0.93.0>) an exception was raised:
    ** (RuntimeError) Resource `PyqRatta.Databank.Question` in relationship `:question` is not in api `PyqRatta.QuizPractice`. Please do one of the following

1. add the resource to the api `PyqRatta.QuizPractice`
2. configure a different api

I can see the relationship can be used for resource in different api.
Here, Red.Accounts.User is in api Red.Accounts and Red.Practice.Card is in api Red.Practice.

Why does it work in case above and not in my case?

when i move resource PyqRatta.QuizPractice.Response to PyqRatta.Databank api, the relationship works. (as suggested by ash)

Ideally, I would like these to be in two separate contexts.

You need to use the api option when doing cross api relationships.

    relationships do
        belongs_to :question, PyqRatta.Databank.Question,
          api: PyqRatta.Databank,
          attribute_writable?: true,
          attribute_type: :integer,
          allow_nil?: false
    end
1 Like

https://hexdocs.pm/ash/relationships.html#relationships-across-apis

Just fo future ref, here are the docs.