Skip to content

ManyToMany #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tronix117 opened this issue Feb 22, 2017 · 1 comment
Open

ManyToMany #5

Tronix117 opened this issue Feb 22, 2017 · 1 comment
Assignees
Labels
Milestone

Comments

@Tronix117
Copy link
Collaborator

ManyToMany needs to be implemented.

Proposed Implementation

User = store.defineMapper('User',{
  endpoint: 'users',
  relations: {
    hasMany: {
      'UserFavorite': {
        localField: 'favorites',
        foreignKey: 'articleId'
      }
    }
  }
});

Article  = store.defineMapper('Article', {
  endpoint: 'articles',
  relations: {
    belongsTo: {
      'User': {
        localField: 'author',
        localKey: 'authorId'
      }
    }
  }
});

UserFavorite = store.defineMapper('UserFavorite', {
  manyToMany: ['User', 'Article']
  relations: {
    belongsTo: {
      'Article': {
        localField: 'article',
        localKey: 'articleId'
      },
      'User': {
        localField: 'user',
        localKey: 'userId'
      }
    }
  }
})
@Tronix117 Tronix117 added this to the v1.0 milestone Feb 22, 2017
@Tronix117 Tronix117 self-assigned this Feb 22, 2017
@quen09t
Copy link

quen09t commented Aug 28, 2017

Class side :

export const Class = store.defineMapper('Class', {
  schema: ClassSchema,
  endpoint: 'classes',
  relations: {
    hasMany: {
      'AppUser': {
        localKeys: 'userIds',
        localField: 'users'
      }
    }
  }
})

User side :

export const AppUser = store.defineMapper('AppUser', {
  schema: AppUserSchema,
  endpoint: 'users',
  relations: {
    hasMany: {
      'Class': {
        foreignKeys: 'userIds',
        localField: 'classes'
      }
    }
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants