question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'belongsToMany' does not exist on type 'typeof ...

See original GitHub issue

Thank you for creating this package!

Reproduction

I created a simple model but the .belongsToMany gives me the error Property 'belongsToMany' does not exist on type 'typeof ...

Steps to reproduce the behavior

  1. Install piniaorm
  2. Create a model (group.ts)
import { Model } from "pinia-orm";

import GroupMember from "./GroupMember";
import Member from "./Member";

export default class Group extends Model {
  static entity = "Group";

  static fields() {
    return {
      id: this.uid(),
      title: this.string(""),
      description: this.string(""),
      members: this.belongsToMany(Member, GroupMember, "group_id", "member_id"),
    };
  }
}
  1. See that your editor (Webstorm in my case) says that belongsToMany does not exist.

Expected behavior

I would expect this.belongsToMany to exist and behave just like the original docs described it. https://vuex-orm.org/guide/model/relationships.html#many-to-many

Actual behavior

It says belongsToMany does not exist.

Additional information

If you didn’t implement belongsToMany it might be good to put this in the README.md

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
svenhuecommented, Apr 16, 2022

If you explain your goal I think we will find an solution 😃

As I understand you want to add a member to a group? If yes, you need the model group and member.

Solution 1: Add an belongsto fields to the member which points to the group model Solution 2: Add the fields hasMany to the group model and point to member

1reaction
khamaileoncommented, Apr 23, 2022

I finally got it to work like this:

const human = store.$repo(Human).new();
const group = store.$repo(Group).new();
const group2 = store.$repo(Group).new();
store.$repo(GroupMembership).fresh([
    { human_id: human.id, group_id: group.id },
    { human_id: human.id, group_id: group2.id }
]);

console.log(store.$repo(Human).withAll().first());
console.log(store.$repo(GroupMembership).withAll().first());

The only problem is that human.groups returns a list of GroupMembership and not groups. I’ll add a method in the model to handle that until the ManyToMany is implemented. By the way I am using vuex-orm next and not pinia yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'User' does not exist on type 'typeof db' sequelize in ...
When I tried to get User from model. I get an error: Property 'User' does not exist on type 'typeof db'. How can...
Read more >
types/sequelize Conflicting exports of Model #16588 - GitHub
This results in Object literal may only specify known properties, and 'classMethods' does not exist in type 'ModelOptions<Model<any, ...
Read more >
Typescript relationships - Forest Admin Developers Community
Model creation error: TypeError: Cannot read property 'companyIdKey' of ... Property 'associate' does not exist on type 'typeof Company'.
Read more >
TypeScript - Sequelize
As Sequelize heavily relies on runtime property assignments, TypeScript won't be very useful out of the box. A decent amount of manual type...
Read more >
sequelize-typescript - npm
The model needs to extend the Model class and has to be annotated with the @Table decorator. All properties that should appear as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found