balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.83k stars 1.95k forks source link

Can't define an One-Way One-to-Many association (cross adapters) #6070

Closed clark0x closed 5 years ago

clark0x commented 10 years ago
//user.js
module.exports = {
      connection: 'dababase'
  attributes: {
    kinappedBy: { collection: 'Alien', dominant: true }
  }
};

//alien.js
module.exports = {
  connection: 'rest-api-based-which-is-readonly'
  attributes: {
    id: { type: 'string', primaryKey: true, required: true, columnName: 'alien_id' }
  }
};

I need to define an One-Way One-to-Many association, something like above. The aliens come from out of space, so there is no way to set a reverse association (adapter is readonly). I expect that waterline stores all kinappers in user's kinappedBy attributes (as an array of id).

But this doesn't work. Waterline parse this as a Many-to-Many association.

CWyrtzen commented 10 years ago

Hi @clarkorz have you found the solution to your problem in another post or tried asking on one of the other forums?

Contribution Guide | Stackoverflow | Google Group | Trello | IRC | Build Status

clark0x commented 10 years ago

@CWyrtzen I have transformed my One-Way Many-to-One association into two associations: a Many-to-One and an One-Way One-to-One. Means, I add a Kinapping Model between User and Alien. Since I define a few more attributes on Kinapping model, not just two ids, so this makes more sense than a Many-to-Many.

But the idea of storing One-to-Many association relations on the One side not the Many side still make sense, especially for no-sql database like mongodb.

uncletammy commented 10 years ago

Hey @clarkorz. Since you got this resolved, I'm going to close this out. If you have an idea as to how we can make this type of associations more intuitive, I encourage you to open an issue with 'Feature Request' in the title explaining how we can make it better.

We are currently changing the way we handle feature requests so it might get shuffled around a bit. Rest assured though, your feedback is very much appreciated and will definitely be considered.