balderdashy / balderdashy/sails

Model configuration `schema` is not taken into account by the populate() query.

Open
#7,207 4 comments 1 reaction 0 assignees View on GitHub
what do you think?
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hello,
I set my model config file with `schema: false` to prevent attributes filtering of the documents retrieved from mongo DB (for different reasons, the models in sails are not always defining all attributes of a document).
But the join document retrieved by a populate() query does not follow that `schema: false` configuration, and the attributes of the joined document **are** filtered according to the model.

For example, in database there are the two documents in different collections:

collection user: { _id: "a user ID", tenant: "a tenant ID", theme: "a theme ID" }
with a sails model like (this is not a real sails model but just an illustration): { id: { type: "string" }, tenant: { model: "Tenant" } }

collection tenant: { _id: "a tenant ID", lang: "fr", configuration: "A configuration" }
with a sails model like (this is not a real sails model but just an illustration): { id: { type: "string" }, configuration: {type: "string"}}

a query like: `sails.models.user.findOne({ id: "a user ID" }).populate('tenant')` returns a user document like:
{ id: "a user ID", theme: "a theme ID", tenant: { id: "a tenant ID", configuration: "A configuration" }}

The `lang` attribute of the tenant has been filtered out as it is not defined by the tenant model, but the `theme` attribute of the user has been preserved as expected.

**Node version**: 14.18.3
**Sails version** _(sails)_: 1.5.2
**ORM hook version** _(sails-hook-orm)_:
**Sockets hook version** _(sails-hook-sockets)_:
**Organics hook version** _(sails-hook-organics)_:
**Grunt hook version** _(sails-hook-grunt)_:
**Uploads hook version** _(sails-hook-uploads)_:
**DB adapter & version** _(e.g. sails-mysql@5.55.5)_: sails-mongo
**Skipper adapter & version** _(e.g. skipper-s3@5.55.5)_:


Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported sails-mongo case from the model configuration using schema: false and a user query with populate('tenant'). Trace how populate() retrieves and filters the joined document, then verify that the populated tenant preserves attributes not declared by its model while the issue's example user behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.