gadelkareem / sails-dynamodb

Amazon DynamoDB adapter for Waterline / Sails.js
http://sailsjs.org
46 stars 22 forks source link

Many to Many Relationships - Are They Supported? #15

Closed bsill closed 8 years ago

bsill commented 8 years ago

I am having trouble saving models which have a many-to-many relationship. Is this supported? I have a many-to-many relationship between users and roles. I have created the join table that sails requires, 'role_users__user_roles' in dynamodb. When I run my migration script to seed the database with an admin user and his corresponding roles, I get the following error:

Waterline Error:  { originalError: 
{ [Error: the value of id is not allowed to be undefined]
 details: [ [Object] ],
 _object: 
  { role_users: '9c7d4258-fdd1-4cd4-a0b7-073a14c70529',
    user_roles: 'f098d269-7815-4c92-bea4-ed3cca63c4f9' },
 message: 'the value of id is not allowed to be undefined' } }

It appears that the dynamodb adapter is not auto-generating the required id field value. I was able to get around this for basic models by generating the uuids in sails based upon the suggestion in another issue thread, however am unsure how to do this for join table entries.

devinivy commented 8 years ago

I think you'll need to use through associations for this. See https://github.com/balderdashy/waterline/issues/705#issuecomment-60945411

For general support of populations, refer to #16 for the feature request.