"OneToOne bidirectional with composite primary keys" cannot populate #3844
Answered
by
daniellam258
daniellam258
asked this question in
Q&A
-
Here are entities @Entity()
export class GamePoolEntity {
@PrimaryKey()
contract_address!: string;
@PrimaryKey()
chain_id!: number;
[PrimaryKeyType]?: [string, number];
@Property()
rpc_url!: string;
@Property()
referral_percents!: number[];
@Property()
referral_campaign_id!: number;
@OneToOne(() => GamePoolScannerEntity, (e) => e.game_pool, {
orphanRemoval: true,
wrappedReference: true,
})
scanner!: Ref<GamePoolScannerEntity>;
@Property({ defaultRaw: 'now()' })
created_at!: Date;
@Property({
onUpdate: () => new Date(),
defaultRaw: 'now()',
})
updated_at!: Date;
}
@Entity()
export class GamePoolScannerEntity {
@OneToOne(() => GamePoolEntity, (e) => e.scanner, {
primary: true,
owner: true,
fieldNames: ['contract_address', 'chain_id'],
wrappedReference: true,
})
game_pool!: Ref<GamePoolEntity>;
[PrimaryKeyType]?: [string, number];
@Property()
start_block!: number;
@Property({ nullable: true })
current_block?: number;
@Property()
min_confirmations!: number;
@Property({ defaultRaw: 'now()' })
created_at!: Date;
@Property({
defaultRaw: 'now()',
onUpdate: () => new Date(),
})
updated_at!: Date;
}
// Find game-pool
const game_pool = await em.findOne(
GamePoolEntity,
{
contract_address: "0x222"
chain_id: 3,
},
{ populate: ['scanner'] },
);
// Find game-pool-scanner
const game_pool_scanner = await em.findOne(GamePoolScannerEntity, {
game_pool: {
contract_address: data.game_pool_contract_address,
chain_id: data.game_pool_chain_id,
},
}); When I query
If I remove the
The 2nd error is kinda interesting, I guess somehow mikro detect changes and execute the change sets. |
Beta Was this translation helpful? Give feedback.
Answered by
daniellam258
Dec 9, 2022
Replies: 1 comment 5 replies
-
I will update an execute and make a pull request soon |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
daniellam258
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I will update an execute and make a pull request soon