Create specific FK on Entity and ManyToMany relation table #4954

Closed
opened 2026-01-22 14:54:00 +01:00 by admin · 3 comments
Owner

Originally created by @malinink on GitHub (Dec 29, 2015).

Originally assigned to: @Ocramius on GitHub.

I have met one problem.
There are Entities in my DB Schema

Project, Type, Factor
Project <m-m> Type
Factor <m-1> Project
Factor <m-1> Type

But, I assume that Factor could be present if and only if there is project-type relation corresponding to it.

The easiest way is to create FK from Factors (project_id, factor_id) to project_factor (m to m relation).

But I didn't find any way to do that.

Am I miss something?

Originally created by @malinink on GitHub (Dec 29, 2015). Originally assigned to: @Ocramius on GitHub. I have met one problem. There are Entities in my DB Schema ``` Project, Type, Factor Project <m-m> Type Factor <m-1> Project Factor <m-1> Type ``` But, I assume that Factor could be present if and only if there is project-type relation corresponding to it. The easiest way is to create FK from Factors (project_id, factor_id) to project_factor (m to m relation). But I didn't find any way to do that. Am I miss something?
admin added the Invalid label 2026-01-22 14:54:00 +01:00
admin closed this issue 2026-01-22 14:54:01 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 29, 2015):

From your wording, this sounds like you want a ProjectType entity that
you can reference from a Factor (non-nullable association).

In OO terms, this would simply mean:

class Project {}
class Type {}
class ProjectType { public function __construct(Project $project, Type
$type) { /* ... _/ } }
class Factor { public function _construct(ProjectType $projectType) { /
... */ } }

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On 29 December 2015 at 11:28, malinink notifications@github.com wrote:

I have met one problem
There are Entities in my DB Schema

Project, Type, Factor
Project Type
Factor Project
Factor Type

But, I assume that Factor could be present if and only if there is
project-type relation corresponding to it

The easiest way is to create FK from Factors (project_id, factor_id) to
project_factor (m to m relation)

But I didn't find any way to do that

Am I miss something?


Reply to this email directly or view it on GitHub
https://github.com/doctrine/doctrine2/issues/5577.

@Ocramius commented on GitHub (Dec 29, 2015): From your wording, this sounds like you want a `ProjectType` entity that you can reference from a `Factor` (non-nullable association). In OO terms, this would simply mean: class Project {} class Type {} class ProjectType { public function __construct(Project $project, Type $type) { /\* ... _/ } } class Factor { public function __construct(ProjectType $projectType) { /_ ... */ } } Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 29 December 2015 at 11:28, malinink notifications@github.com wrote: > I have met one problem > There are Entities in my DB Schema > > Project, Type, Factor > Project <m-m> Type > Factor <m-1> Project > Factor <m-1> Type > > But, I assume that Factor could be present if and only if there is > project-type relation corresponding to it > > The easiest way is to create FK from Factors (project_id, factor_id) to > project_factor (m to m relation) > > But I didn't find any way to do that > > Am I miss something? > > — > Reply to this email directly or view it on GitHub > https://github.com/doctrine/doctrine2/issues/5577.
Author
Owner

@malinink commented on GitHub (Dec 29, 2015):

@Ocramius
Thanks for the answer. Yes it is one of the way it could be done in doctrine. But, Actually there is some addition information about that DB.

We need Factor depend on Project directly (There is one on the common operation to retrieve all factors of Project). In The case that you are providing it is some overhead to do that.
Also new object adds more actions inside business logic in project - types relations.

May be there is any opportunity not to remove an exists FK, or add it manually?

I think that also there could be Entity configuration that supports multiple FK on one property. Isn't it?

Thank you!
P.S. Actually that DB Schema is result of denormalization process.

@malinink commented on GitHub (Dec 29, 2015): @Ocramius Thanks for the answer. Yes it is one of the way it could be done in doctrine. But, Actually there is some addition information about that DB. We need Factor depend on Project directly (There is one on the common operation to retrieve all factors of Project). In The case that you are providing it is some overhead to do that. Also new object adds more actions inside business logic in project - types relations. May be there is any opportunity not to remove an exists FK, or add it manually? I think that also there could be Entity configuration that supports multiple FK on one property. Isn't it? Thank you! P.S. Actually that DB Schema is result of denormalization process.
Author
Owner

@Ocramius commented on GitHub (Dec 29, 2015):

On 29 December 2015 at 14:37, malinink notifications@github.com wrote:

I think that also there could be Entity configuration that supports
multiple FK on one property. Isn't it?

Not really: you reference one thing, therefore you should have one FK.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

@Ocramius commented on GitHub (Dec 29, 2015): On 29 December 2015 at 14:37, malinink notifications@github.com wrote: > I think that also there could be Entity configuration that supports > multiple FK on one property. Isn't it? Not really: you reference one thing, therefore you should have one FK. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4954