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

[BUG] ORM Returning null for random fields #36

Open
bramirez96 opened this issue Jan 19, 2021 · 1 comment
Open

[BUG] ORM Returning null for random fields #36

bramirez96 opened this issue Jan 19, 2021 · 1 comment

Comments

@bramirez96
Copy link

bramirez96 commented Jan 19, 2021

Running the following query:

const user = await this.db
  .getManager()
  .query(User)
  .where('email', email)
  .first();

Returns the following object:

User {
  id: 3,
  codename: "SomeCodename",
  email: "[email protected]",
  password: "$2a$08$ckrMPfkyeT0Lat2Ajadd0OtnUBxi0ryHpWlxOqHNGb8I8.gAVKULK",
  age: 24,
  createdAt: 2021-01-19T01:02:02.000Z,    
  updatedAt: 2021-01-19T01:02:02.000Z,    
  parentEmail: null,
  roleId: null,
  isValidated: null
}

In PGAdmin, the parentEmail, roleId, and isValidated fields are all set. Unsure why this is happening, as updating the fields through the ORM seems to be working correctly? For instance, I'm able to sign a user up with ORM and show all fields correct in PGAdmin, then I'm able to update validation status correctly. When I run this query though, those 3 fields are always null.

I'm using the latest release of Cotton (0.7.5) and running Deno v1.6.3.

For reference, the User model looks like this:

@Model('users')
export default class User {
  @Primary()
  id!: number;

  @Column({ type: DataType.String })
  codename!: string;

  @Column({ type: DataType.String })
  email!: string;

  @Column({ type: DataType.String })
  parentEmail!: string;

  @Column({ type: DataType.String })
  password!: string;

  @Column({ type: DataType.Number })
  age!: number;

  @Column({ type: DataType.Number })
  roleId!: number;

  @Column({ type: DataType.Boolean })
  isValidated!: boolean;

  @Column({ type: DataType.Date, default: () => new Date().toUTCString() })
  createdAt!: Date;

  @Column({ type: DataType.Date, default: () => new Date().toUTCString() })
  updatedAt!: Date;

  @BelongsTo(() => Role, 'roleId')
  role!: Role;

  @HasMany(() => User, 'userId')
  validations!: Validation[];

  public generateFrom(body: INewUser) {
    this.age = body.age;
    this.codename = body.codename;
    this.email = body.email;
    this.parentEmail = body.parentEmail;
    this.password = body.password;
    this.roleId = body.roleId;
  }
}
@bramirez96
Copy link
Author

Data in PGAdmin:

parentEmail: '[email protected]',
isValidated: true,
roleId: 1

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

No branches or pull requests

1 participant