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

OneToOne relation with referencedColumnName does not work #341

Closed
JacobSoderblom opened this issue Mar 13, 2017 · 3 comments
Closed

OneToOne relation with referencedColumnName does not work #341

JacobSoderblom opened this issue Mar 13, 2017 · 3 comments
Labels

Comments

@JacobSoderblom
Copy link

JacobSoderblom commented Mar 13, 2017

We are trying to create a OneToOne relation with referencedColumnName where the relation is not between primary keys, its between two unique strings. See example below

@Entity()
class Exercise {
  
  @PrimaryGeneratedColumn()
  public id: number;

  @Column('string')
  public key: string;

  @OneToOne((type) => Atom, (atom) => atom.exercise)
  public atom: Atom;
}

@Entity()
class Atom {

  @PrimaryGeneratedColumn()
  public id: number;

  @Column('string')
  public key: string;

  @Column('string')
  public exercise_key: string;

  @OneToOne((type) => Exercise, (exercise) => exercise.atom)
  @JoinColumn({ name: 'exercise_key',  referencedColumnName: 'key' })
  public exercise: Exercise
}

When typeorm tries to create the schema we get an error saying that MySQL could not create the foreign key. We debugged it and saw that ForeignKeySchema.referencedColumnNames = ['id'] and not ForeignKeySchema.referencedColumnNames = ['key'], but I don't know if that's a part of the problem.

@JacobSoderblom
Copy link
Author

@pleerock ping

pleerock pushed a commit that referenced this issue Mar 24, 2017
@pleerock pleerock added the bug label Mar 24, 2017
@pleerock
Copy link
Member

that was a bug. Fixed and released in 0.0.11. Make sure to setup your entities exactly like in test in 08c1ee1

@JacobSoderblom
Copy link
Author

JacobSoderblom commented Mar 24, 2017 via email

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

2 participants