Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#138): Load embedded entities #267

Merged
merged 3 commits into from
Oct 2, 2019

Conversation

frco9
Copy link
Contributor

@frco9 frco9 commented Sep 19, 2019

This PR fixes #138

Embedded entities were not loaded as the complete path to them was not used in the select.

@michaelyali
Copy link
Member

@frco9 thanks!
What about adding tests?

@frco9
Copy link
Contributor Author

frco9 commented Sep 19, 2019

Yep I'm just finishing them now, it will be ready in ~5min ;)

@frco9
Copy link
Contributor Author

frco9 commented Sep 19, 2019

@zMotivat0r here they are, tell me if you want me to change something !

@michaelyali michaelyali requested a review from Diluka September 19, 2019 09:31
@michaelyali
Copy link
Member

LGTM. Let's @Diluka to take a look too. Thanks!

Copy link
Contributor

@Diluka Diluka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@frco9
Copy link
Contributor Author

frco9 commented Sep 20, 2019

@zMotivat0r do you think you'll merge and release that soon ?

@LoicMahieu
Copy link

Hi! Many thanks @frco9
I confirm it works perfectly 👍

@michaelyali michaelyali merged commit 56508f3 into nestjsx:master Oct 2, 2019
@jopdorp
Copy link

jopdorp commented Oct 15, 2019

@zMotivat0r
doesn't work yet if the embedded field is in an entity that is joined:
http://localhost:3000/page/?join=routes

where the route entity has an embedded entity:
@column(type => AbTest)
abTest: AbTest;

there the embedded entity will still not be loaded

@michaelyali
Copy link
Member

@jopdorp could you please show me your entities, I didn't get it :(

@jopdorp
Copy link

jopdorp commented Oct 15, 2019

@zMotivat0r

Page:

import {
Column,
Entity,
Generated,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Page } from '../page/page.entity';
import {AbTest} from "./abtest.entity";
import {Utm} from "./utm.entity";

@entity()
export class Route {

@PrimaryGeneratedColumn()
id: number;
@generated('uuid')
@column()
uuid: string;
@manytoone(type => Page)
from: Page;
@manytoone(type => Page)
to: Page;
@column(type => Utm)
utm: Utm;
@column(type => AbTest)
abTest: AbTest;
@column({type: 'jsonb', nullable: true })
dmp: object;

constructor(from: Page, to: Page) {
this.from = from;
this.to = to;
}
}

AbTest:

import {Column } from 'typeorm';

export class AbTest {
@column({ nullable: true })
testId: string;
@column({ nullable: true })
variant: string;
@column({ nullable: true })
variantName: string;
@column({ nullable: true })
name: string;
@column({ nullable: true })
traffic: number;
}

page controller:

import { Controller } from '@nestjs/common';
import { Crud } from '@nestjsx/crud';
import {PageService} from "./page.service";
import {Page} from "./page.entity";
import { ApiUseTags } from '@nestjs/swagger';

@crud({
model: {
type: Page,
},
query: {
join: {
routes: {
eager: false
}
}
}
})

@ApiUseTags('Page')
@controller('page')
export class PageController {
constructor(public service: PageService) {}
}

@jopdorp
Copy link

jopdorp commented Oct 15, 2019

@zMotivat0r

so i would expect the route as join on in page request to contain the embedded data

the request and responses:

this doesn't load the embedded utm and abTest
http://localhost:3000/page/259?join=routes

{
name: "Bike",
content: "{}",
id: 259,
uuid: "3fce2caa-5fca-42c1-9695-f9dc8c6152b2",
routes: [
{
id: 259,
uuid: "f7fa2b8a-045f-45f1-8354-185d8a78c5a7",
dmp: null
}
]
}

this loads the embedded utm and abTest
http://localhost:3000/route/259
{
id: 259,
uuid: "f7fa2b8a-045f-45f1-8354-185d8a78c5a7",
dmp: null,
utm: {
source: "gool",
collaboration: null,
content: null,
medium: null,
term: null
},
abTest: {
testId: null,
variant: null,
variantName: null,
name: null,
traffic: null
}
}

@jopdorp
Copy link

jopdorp commented Oct 18, 2019

@zMotivat0r does it make any sense now?

@michaelyali
Copy link
Member

@jopdorp fixed in v4.6.0
Please let me know if it's still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot load embedded entities
5 participants