samedi 2 janvier 2016

Sails/ Waterline: Ids of associations in query result not accessible without populate

I am to a fair degree familiar with Sails and Waterline.

Situation:

  • We have a Model Playlist with a many-to-many association to the Model Song on sails-mongo.
  • When we query for all playlists, we do not want to sideload all associated songs, we just need the ids of the associated songs so that we can load them lazily later.
  • When we do a populate (with Ember blueprints: populateEach()) we of course get the ids, but it takes around 1s for loading all the Playlists.
  • Without populate it is just around 50ms.

Complication:

  • After getting the results with query.exec WITHOUT populate, the ids of the associated songs are not included and not sent back to the requester.
  • But I can log the ids of associated records to the console via iterating over Object.keys(matchingRecord).
  • I can set them to a new property of the matchingRecord, all without populating.
  • However, I cannot explicitly set them to their property name.
  • Using the original property name is required for the interaction with the Ember frontend.
  • I tried to mess around with Object.defineProperty - no success. I guess the set/get functions are overwritten to prevent that.

Questions:

  • How can I make those id arrays of visible/prevent that they are hidden/removed?
  • Are there any other ideas from your side to maneuver around this issue?

Thank you, Manuel




Aucun commentaire:

Enregistrer un commentaire