question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EntityFactory using .map give me an error

See original GitHub issue

I ran the example (User and Pet) that you have here and I am getting this error:

(property) User.pets: Pet[] This expression is not callable. Type 'Pet[]' has no call signatures.

I used this as seeder:

await factory(User)() .map(async (user: User) => { const pets: Pet[] = await factory(Pet)().createMany(2) const petIds = pets.map((pet: Pet) => pet.Id) await user.pets().attach(petIds) }) .createMany(5)

Any idea?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

4reactions
SaveYourTimecommented, Jul 1, 2020

I look up the source code, nothing is related to the attach method. Finally, I use the following way to achieve that

seeds

/src/database/seeds/create-users.seeds.ts

import { Factory, Seeder } from 'typeorm-seeding';
import { User } from '../../users/user.entity';
import { Task } from '../../tasks/task.entity';

export default class CreateUsers implements Seeder {
  public async run(factory: Factory): Promise<any> {
    const users = await factory(User)().createMany(10);

    for (const user of users) {
      const { id } = user;

      await factory(Task)({ id }).create();
    }
  }
}

factory

/src/database/factories/task.factory.ts

import Faker from 'faker';
import { define } from 'typeorm-seeding';
import { Task } from '../../tasks/task.entity';
import { TaskStatus } from '../../tasks/task-status.enum';

interface Context {
  id: number;
}

define(Task, (faker: typeof Faker, context: Context) => {
  const { id } = context; // <--- here!

  const title = faker.lorem.words();
  const description = faker.lorem.paragraph();
  const status = faker.random.objectElement<TaskStatus>(TaskStatus);

  const task = new Task();
  task.title = title;
  task.description = description;
  task.status = status;
  task.userId = id; // <--- here!
  return task;
});
0reactions
AmrAbdalrahmancommented, Jul 14, 2021

I look up the source code, nothing is related to the attach method. Finally, I use the following way to achieve that

seeds

/src/database/seeds/create-users.seeds.ts

import { Factory, Seeder } from 'typeorm-seeding';
import { User } from '../../users/user.entity';
import { Task } from '../../tasks/task.entity';

export default class CreateUsers implements Seeder {
  public async run(factory: Factory): Promise<any> {
    const users = await factory(User)().createMany(10);

    for (const user of users) {
      const { id } = user;

      await factory(Task)({ id }).create();
    }
  }
}

factory

/src/database/factories/task.factory.ts

import Faker from 'faker';
import { define } from 'typeorm-seeding';
import { Task } from '../../tasks/task.entity';
import { TaskStatus } from '../../tasks/task-status.enum';

interface Context {
  id: number;
}

define(Task, (faker: typeof Faker, context: Context) => {
  const { id } = context; // <--- here!

  const title = faker.lorem.words();
  const description = faker.lorem.paragraph();
  const status = faker.random.objectElement<TaskStatus>(TaskStatus);

  const task = new Task();
  task.title = title;
  task.description = description;
  task.status = status;
  task.userId = id; // <--- here!
  return task;
});

thanks, works well with me . my once editing to solve the error was shown to me is making (faker: typeof Faker, context: ViewInterface | any)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error creating bean with name 'entityManagerFactory' defined ...
I would start by adding the following dependency: <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.4.
Read more >
Error creatigng EntityManagerFactory - CodeRanch
Hi, I'm trying to use the JBoss JPA, which is hibernate. Whenever I try to create/inject the EntityManagerFactory or the PersistenceContext it keeps ......
Read more >
Error creating bean with name entityManagerFactory defined ...
In this post, we will see the possible reasons and fixes for the 'Error creating bean with name entityManagerFactory defined in class path ......
Read more >
Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Ultimately the application domain model is the central character in an ORM. They make up the classes you wish to map. Hibernate works...
Read more >
Spring Data for Apache Cassandra - Reference Documentation
In this section, we try to provide what we think is an ... The same applies to the definition of the EntityManagerFactory bean....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found