Comments (5)
No you can't. I told you to swap those, so where you have mappedBy
you will have inversedBy
and vice versa.
Btw I thought the inversedBy was supposed to be used in the owning side.
Yes, and you had it on the inverse instead. The owning side is where you have the database column.
FYI the inverserBy
is actually optional, the owning side does not need to point anywhere, only the inverse side needs to specify the mappedBy
option.
from nestjs.
Additional info below:
Profile Schema
import { BigIntType, EntitySchema } from '@mikro-orm/core';
import { Profile } from './profile.entity';
import { User } from './user.entity';
export const profileSchema = new EntitySchema<Profile>({
class: Profile,
tableName: 'profile',
forceConstructor: true,
properties: {
id: {
type: BigIntType,
primary: true,
autoincrement: true,
},
user: {
entity: () => User,
reference: '1:1',
mappedBy: 'profile',
ref: true,
},
imageUrl: {
type: String,
},
},
});
User Schema
import { BigIntType, EntitySchema } from '@mikro-orm/core';
import { User } from './user.entity';
import { Address } from './address.entity';
import { Profile } from './profile.entity';
export const userSchema = new EntitySchema<User>({
class: User,
tableName: 'user',
forceConstructor: true,
properties: {
id: {
type: BigIntType,
primary: true,
autoincrement: true,
},
firstName: {
type: 'string',
},
lastName: {
type: 'string',
},
email: {
type: 'string',
},
addresses: {
reference: '1:m',
entity: () => Address,
mappedBy: 'user',
},
profile: {
reference: '1:1',
entity: () => Profile,
inversedBy: 'user',
nullable: true,
},
createdAt: {
type: 'timestamp',
},
updatedAt: {
type: 'timestamp',
},
},
});
from nestjs.
because it is inverse side, as such it does not represent any database column. your schema is not in sync with entity definition apparently, if you expect such column to exist. swap inversedBy
with mappedBy
(in both entities)
from nestjs.
Hey Martin, thanks for the speedy reply! But can we define mappedBy
in both entities? I actually get this error when I do so:
MetadataError: Both User.profile and Profile.user are defined as owning sides, use 'mappedBy' on one of them
Btw I thought the inversedBy
was supposed to be used in the owning
side. What is it's purpose instead?
from nestjs.
Got it! Thanks, Martin!
from nestjs.
Related Issues (20)
- IdentityMap Request Context fails in NestJS app when using `app.setGlobalPrefix` HOT 7
- Metadata for entity CustomBaseEntity not found HOT 4
- MetadataError: Duplicate entity names are not allowed: "User" HOT 7
- Entity id is not populated HOT 23
- Error when trying to query an entity from the repository HOT 3
- How can I take some actions after it successfully connects or fails? HOT 1
- Cannot persist Read-Only association HOT 3
- Cannot get `@UseRequestContext` to work in a REQUEST scoped BullMQ processor HOT 4
- Populating Nested Field returns the wrong number of associated entities HOT 5
- Relations not working in nestjs HOT 6
- Issue when running tests after upgrading to 5.2.2
- Bump version, compatible with MikroORM V6 HOT 6
- Nestjs, mikro-orm and postgres can't generate table automatically HOT 2
- vitest + mikroorm collection error HOT 4
- findByCursor method not working on sqlite HOT 1
- Testing with multiple testing modules in NestJS and Jest leads to an error during metadata discovery HOT 2
- Issues running Mikro-ORM with NestJS on Vercel platform HOT 1
- MikroOrmMiddleware not found in e2e tests
- feat: add Transactional Decorator HOT 1
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 nestjs.