Skip to content

Relations don't use namespace to make/retrieve related model #1740

@alvaro-canepa

Description

@alvaro-canepa

Environment

pinia-orm: 1.7.2
Vite: 4.5.0
Vue: 3.3.6
Typescript: 5.2.2

Reproduction

Main User model

// models/main/User.ts
import { Model } from 'pinia-orm'

export default class User extends Model {
  static entity = 'users';
  static namespace = 'main';

  static fields() {
    return {
      id: this.uid(),
      name: this.string(''),
      age: this.number(null),
    }
  }
}

Extended User model from another namespace

// models/extended/User.ts
import { Model } from 'pinia-orm';
import MainUser from '@/models/main/User';

export default class User extends Model {
  static entity = 'users';
  static namespace = 'extended';

  static fields() {
    return {
      id: this.uid(),
      user_id: this.attr(''),
      user: this.belongsTo(MainUser, 'user_id'),
//      ... more fields
    }
  }
}

Make relation

import User from '@/models/extended/User';

const user = useRepo(User).make({
    user: {
      name: 'John Doe',
      age: 30
    }
});

Describe the bug

When make a model with related one as same entity but different namespace, results was a related model as a same of parent (like it was category and child category).

To solve this, entity must be unique per model. If I not wrong, related models must use $storeName() instead of $entity().

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions