Comments (8)
Discord Thread: https://discord.com/channels/1214904142443839538/1238875455436881971
from mikro-orm.
A workaround for your repro would be using em.populate
, which will adjust the user
entity populate hint internally and that is the main source when serializing now. The _populated
flag is only meant for manual overrides (via the public populated()
method, no need to access it directly).
await orm.em.populate(user, ['groups.permissions'], {
where: {
groups: {
permissions: {
write: true,
},
},
},
orderBy: {
groups: {
permissions: {
id: 'ASC',
},
},
},
});
Note that you need to call this on the root entity (user
) which you will be serializing, it wouldn't help if called on user.groups
separately.
from mikro-orm.
Will it affect the loaded groups? I have a where condition on those as well?
from mikro-orm.
Why don't you check the query yourself? It should be equivalent (it's actually a better approach in general).
from mikro-orm.
@B4nan, how can I limit populate from populating an entire collection? I want to just take 1 for example.
from mikro-orm.
So, here is a conversion of your suggestion:
await this.repo.populate(
user,
['pictures', 'profiles.links', 'profiles.themes', 'profiles.groups', 'settings'], // here, I want to get the last applied settings by the user
{
orderBy: {
profiles: {
links: {
urlOrder: 'ASC'
}
},
pictures: {
sizes: 'ASC'
}
},
where: {
profiles: {
links: {
publish: true
},
themes: {
default: true
}
}
}
}
);
from mikro-orm.
Hello @B4nan , have you had a chance to see my comment above? Is there any chance I limit the populate for settings
? I used to be able to do this easy with matching
.
from mikro-orm.
you can't do that with em.populate
, that only loads complete collections.
i think i have a workaround for you, you could use setSerializationContext
private method of EntityLoader, that is what makes it work with em.populate
:
await users[0].groups.matching({ ... });
// @ts-ignore accessing private variables and methods
orm.em.entityLoader.setSerializationContext(users, [{ field: 'groups', children: [{ field: 'permissions' }] }], {});
from mikro-orm.
Related Issues (20)
- Add SurrealDB support
- https://mikro-orm.io/ is down HOT 2
- `RequiredEntityData<T>` does not allow null value for optional properties HOT 1
- EntityRepository not persisting Entities when using `find` and flush after property update.
- Not able to populate relation on a loaded entity HOT 4
- EntityDTO maps one-to-many relationships to arrays of strings
- Native BigInt PK returns string instead of number
- `MikroORM config file not found` after update to `6.3.0`
- Example with BUN.
- If I use Date as PrimaryKey and create 2 records in the same seconds...
- Incorectly generated migration when using default value in embeddable entity HOT 3
- Embedded lazy field not populated despite specifying it in `populate`
- Relation to STI has wrong 'mappedBy' reference type HOT 3
- Only abstract entities are discovered after upgrading MikroORM version
- I can't get the env variables to load
- feat(entity-generator): Use more human readable relation names in EntityGenerator HOT 2
- how to use Filter?
- NamingStrategy manyToMany relation name API HOT 3
- PopulateWhere does not work with nested filter query
- docs: add eventArgs to lifecycle hooks examples
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mikro-orm.