adonisjs / core

AdonisJS is a TypeScript-first web framework for building web apps and API servers. It comes with support for testing, modern tooling, an ecosystem of official packages, and more.
https://adonisjs.com
MIT License
16.88k stars 638 forks source link

Inverse relation not working #1078

Closed php-wmt-sujal closed 5 years ago

php-wmt-sujal commented 5 years ago

I have 3 model Country, State, City country.js

  state () {
    return this.hasMany(State, 'id', 'country_id')
  }

state.js

 city () {
    return this.hasMany(City, 'id', 'state_id')
  }
  stateCountry () {
    return this.belongsTo(Country, 'country_id', 'id')
  }

city.js

cityState () {
    return this.belongsTo(State, 'state_id', 'id')
  }

Now I'm trying to get two type of data

  1. From country > state > city ( normal relation )
  2. From city > state > country ( inverse relation )
case 1:
const countries = await Country.query()
          .with('state.city')
          .fetch()
case 2:
const citties = await City.query()
      .with('cityState.stateCountry')
      .fetch()

Now whichever I run first will work and give me proper result however running second case throw 500 Error

this.RelatedModel.query is not a function

Now If I restart the server and run the second case it'll work and the first one will stop working. Kindly help we're facing this issue. look like some kind of caching in issue in a query or in model ORM.

php-wmt-sujal commented 5 years ago

https://github.com/adonisjs/adonis-lucid/issues/440

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.