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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃挕 Foreign Keys as Primary Key #415

Open
gam6itko opened this issue Jun 15, 2023 · 4 comments
Open

馃挕 Foreign Keys as Primary Key #415

gam6itko opened this issue Jun 15, 2023 · 4 comments
Assignees
Labels
status:to be verified Needs to be reproduced and validated. type:feature New feature.

Comments

@gam6itko
Copy link
Contributor

I have an idea!

It would be very useful to use one field instead of two like in Doctrine.

Something like...

class User {
    #[Cycle\Column(type: 'primary')]
    private ?int $id = null;

    #[Cycle\Relation\HasOne(target: UserOneLove::class)]
    private UserOneLove $oneLove;
}

class UserOneLove {
    #[Cycle\PrimaryKey()]
    #[Cycle\Relation\BelongsTo(target: User::class, innerKey: 'user_id')]
    private User $user;
}
@gam6itko gam6itko added the type:feature New feature. label Jun 15, 2023
@gam6itko
Copy link
Contributor Author

gam6itko commented Mar 1, 2024

UPDATED
the workaround for this case.

class User {
    #[Cycle\Column(type: 'primary')]
    private ?int $id = null;

    #[Cycle\Relation\HasOne(target: UserOneLove::class, outerKey: 'user_id',  indexCreate: false)]
    private UserOneLove $oneLove;
}

class UserOneLove {
    #[Cycle\Column(type: 'primary', name: 'user_id')]
    private ?int $user_id = null;

    #[Cycle\Relation\BelongsTo(target: User::class, innerKey: 'user_id', indexCreate: false)]
    private User $user;
}

@roxblnfk
Copy link
Member

roxblnfk commented Mar 4, 2024

In your examples innerKey and outerKey should contain property name, not column name

@roxblnfk roxblnfk added the status:to be verified Needs to be reproduced and validated. label Mar 4, 2024
@rauanmayemir
Copy link
Contributor

I actually use this sometimes and it works fine. You still do need to declare the field on the child entity as it's a separate column, I don't see a problem with that.

@rauanmayemir
Copy link
Contributor

Also, keep in mind that starting from PHP 8.2 dynamic properties will start giving you a headache, so it's better to have them declared explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:feature New feature.
Projects
Status: Backlog
Development

No branches or pull requests

3 participants