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

Load eager relation data in GET request #232

Closed
dulkith opened this issue Aug 27, 2019 · 3 comments
Closed

Load eager relation data in GET request #232

dulkith opened this issue Aug 27, 2019 · 3 comments
Assignees

Comments

@dulkith
Copy link

dulkith commented Aug 27, 2019

@Crud({
  model: {
    type: Gate,
  },
})
@ApiUseTags('Gate')
@Controller('gate')
export class GateController {
  constructor(public service: GateService) {
  }
}
@Injectable()
export class GateService extends TypeOrmCrudService<Gate> {
  constructor(@InjectRepository(Gate) repo) {
    super(repo);
  }
}
@Entity()
export class Gate {
  @ApiModelProperty()
  @PrimaryGeneratedColumn()
  id: number;

  @ApiModelProperty()
  @Column()
  name: string;

  @ManyToOne(type => School, school => school.gates, {
    eager: true,
  })
  @JoinColumn({ name: 'school_id' })
  school: School;
}

How to get out put as a eager.

@bashleigh bashleigh self-assigned this Aug 27, 2019
@bashleigh
Copy link
Collaborator

Yo! Thanks for the question!
You can load eager relations like so

@Crud({
  model: {
    type: Gate,
  },
  query: {
    joins: {
      school: {
        eager: true,
      },
    },
  },
})

@dulkith
Copy link
Author

dulkith commented Aug 27, 2019

@Crud({
  model: {
    type: Gate,
  },
  query: {
    joins: {
      school: {
        eager: true,
      },
    },
  },
})

Thank you for the help! It works.
Another problem is, how to give swagger support for this. its show sample output as like =>
`

[
{
"id": 0,
"title": "string",
}
]`
And eager between 3 relational classes not load.

@Diluka
Copy link
Contributor

Diluka commented Aug 28, 2019

typeorm is going to deprecate eager and lazy loading
see typeorm/typeorm#3251

@dulkith dulkith closed this as completed Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants