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

Error after extending User type and migration generation #615

Open
kfrajtak opened this issue Mar 15, 2019 · 1 comment
Open

Error after extending User type and migration generation #615

kfrajtak opened this issue Mar 15, 2019 · 1 comment
Labels

Comments

@kfrajtak
Copy link

Hi,

I have extended the User entity as described here:

import { Entity, Column } from "typeorm";
import { User as AccountsUser } from "@accounts/typeorm";

@Entity()
export class User extends AccountsUser {
  @Column() firstName: string;
  @Column() lastName: string;
  @Column({ type: "blob" }) profileImage: string;
}

Then I tried to generate migrations using with

npm run typeorm migration:generate -- -n 20190315.js

where typeorm is defined in package.json as follows

"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js"

and got this error

Error: Entity metadata for User#allServices was not found. Check if you specified a correct entity object and if it's connected in the connection options.

Can you help me with this problem?

Thank you,
Karel

@chewnoill
Copy link

I think you need still to tell typeorm where Account's entity definitions are, ie:

ormconfig.json:

...
   "entities": [
     "node_modules/@accounts/typeorm/lib/entity/*.js",
     "src/models/**/*.ts"
   ],
...

Then you can extend the User class as described in the documentation:

import { Entity, Column} from "typeorm";
import { User as AccountsUser } from "@accounts/typeorm";

@Entity()
export class User extends AccountsUser {
    @Column()
    public foo: string;
}

note the migration will generate, user_session, user_email, and user_service tables at the same time, which I assume are required, and the root of this problem.

As long as you don't mind naming your user table user this approach should work(?).

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

No branches or pull requests

3 participants