Vuex ORM manyToMany relationship

hi all, i am trying to query a model with many to many relationship but it gets undefined

herein my models


// account model

export default class Account extends Model {

    static entity = "accounts"

    static fields(){
        return {
            id: this.increment(),
            name: this.attr({
                ar: this.string(null),
                en: this.string(null)
            }),
            currency: this.string(null),
            commission: this.attr(null),
            accountInfo: this.string(null),
            invoices: this.hasMany(Invoice, "account_id"),
            transactions: this.hasMany(Transaction, "account_id"),
            users: this.belongsToMany(User, AccountUser, "account_id", "user_id")
        }
    }

}

// user model

export default class User extends Model {
    static entity = "staff"

    static fields(){
        return {
            id: this.increment(),
            role: this.attr(),
            first_name: this.string(),
            last_name: this.string(),
            email: this.string(),
            accounts: this.belongsToMany(Account, AccountUser, "user_id", "account_id")
        }
    }

}

// this is the pivot model

export default class AccountUser extends Model {
    static entity = "account-users"

    static primaryKey = ["user_id", "account_id"]

    static fields() {
        return {
            user_id: this.attr(),
            account_id: this.attr(),
        }
    }
}

// in vue component trying to query in a computed

 computed: {
    fetchAccounts: {
      get() {
        return Account.query().with("users").all();
      },
      set(newVal) {}
    },
  },

the problem is ‘users’ gets undefined and the same for ‘accounts’ while trying to query the user model with accounts


data() {
    return {

       users: User.query().with("accounts").all()
 
      }
}

thanks in advance

Have you tested your classes and your coding design outside of Vue to ensure that is working?

Also for your users I see you have date() which I’m assuming should be data()

Iv never seen Classing done like that - could be inexperience of mine but maybe have a double check that your implementation is correct.

I recommended trying your queries by themselves to ensure you are getting data first to know what is working. And then slowly implementing that into Vue.

Hope this was helpful.

it is just a typo, while trying to write the question

i just used to write it this way

i tried and it works fine the problem starts just when trying to query with the relationship , actually it is my first time to use many to many relationship so i think the problem is in this part.

thank u

I think you need to switch “account_id” and “user_id” in your users property.