Custom Many-To-Many relation in DoctrineUndefined index on doctrine m:n relationEntityAudit - Doctrine2: Using the same entity in both OneToMany and OneToOne possibleIssues in entities from different bundles using different entity managersdoctrine 2 many to many with translationhow to add column in table using doctrine symfony2Symfony2 doctrine join returns too much dataPropper entity associations mapping with one entity for join table (Doctrine 2)Doctrine :: Relation ManyToOne will not workDoctrine2 relation for non Id columnHow to fix broken doctrine relations?
Creating chess engine, machine learning vs. traditional engine?
Is there such thing as plasma (from reentry) creating lift?
useState hook setter incorrectly overwrites state
What does IKEA-like mean?
How to find out which object is taking space?
How to make "acts of patience" exciting?
Can one use mythology to study the history of a region?
How could "aggressor" pilots fly foreign aircraft without speaking the language?
Why didn't Kes send Voyager home?
Is it fine to ask this kind of question to the corresponding author of a paper?
Can you pitch an outline?
Overlay image with parts of another image
Modify real part and leaves imaginary part unchanged
RTL8723DE Working with signal, but never connects
Was Wayne Brady considered a guest star on "Whose Line Is It Anyway?"
Would my post-apocalyptic US Government be able to work and function properly?
Why can I ping 10.0.0.0/8 addresses from a 192.168.1.0/24 subnet?
Conveying the idea of " judge a book by its cover" by " juger un livre par sa couverture"
What do you call the fallacy of thinking that some action A will guarantee some outcome B, when in reality B depends on multiple other conditions?
Can I use I2C over 2m cables?
What does ぎゃんかわ女子 mean?
Difference between $HOME and ~
Can I perform Umrah while on a Saudi Arabian visit e-visa
What is this dial on my old SLR for?
Custom Many-To-Many relation in Doctrine
Undefined index on doctrine m:n relationEntityAudit - Doctrine2: Using the same entity in both OneToMany and OneToOne possibleIssues in entities from different bundles using different entity managersdoctrine 2 many to many with translationhow to add column in table using doctrine symfony2Symfony2 doctrine join returns too much dataPropper entity associations mapping with one entity for join table (Doctrine 2)Doctrine :: Relation ManyToOne will not workDoctrine2 relation for non Id columnHow to fix broken doctrine relations?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
Let's say I want to implement the following entities in Doctrine:
Thing
represents anything that can perform an action over another Thing
. A Relation
can contain two entities and a description of the action, and its tuple is unique.
Here are some examples of what I'm trying to achieve:
- Hens (thing) lay (action) eggs (thing)
- Water (thing) extinguishes (action) fire (thing)
- Bob (thing) likes (action) apples (thing)
- Bob (thing) drinks (action) water (thing)
As you can see, order matters (it's not the same "Bob likes apples" as "Apples like Bob").
Despite my best efforts, I can't find any proper way to implement this.
I've tried creating a field called $relations
in Thing
tagged as "One-To-Many" and then marking $left
and $right
in Relation
as "Many-To-One". The problem is I can't have two inversed sides for the same owning side (at least AFAIK).
This current implementation neither allows for getting all relations for a particular Thing
in the $relations
field as I'm only able to specify one inversed side.
Here's what I've come up with so far:
/** @ORMEntity */
class Thing
/**
* @ORMId
* @ORMColumn(type="integer", options="unsigned":true)
* @ORMGeneratedValue
*/
protected $id;
/** @ORMColumn(type="string") */
protected $name;
/**
* @ORMOneToMany(targetEntity="Relation", mappedBy="right")
*/
protected $relations;
/** @ORMEntity */
class Relation
/** @ORMId @ORMColumn(type="string") */
protected $action;
/** @ORMId @ORMManyToOne(targetEntity="Thing") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relations") */
private $right;
php doctrine-orm doctrine
add a comment
|
Let's say I want to implement the following entities in Doctrine:
Thing
represents anything that can perform an action over another Thing
. A Relation
can contain two entities and a description of the action, and its tuple is unique.
Here are some examples of what I'm trying to achieve:
- Hens (thing) lay (action) eggs (thing)
- Water (thing) extinguishes (action) fire (thing)
- Bob (thing) likes (action) apples (thing)
- Bob (thing) drinks (action) water (thing)
As you can see, order matters (it's not the same "Bob likes apples" as "Apples like Bob").
Despite my best efforts, I can't find any proper way to implement this.
I've tried creating a field called $relations
in Thing
tagged as "One-To-Many" and then marking $left
and $right
in Relation
as "Many-To-One". The problem is I can't have two inversed sides for the same owning side (at least AFAIK).
This current implementation neither allows for getting all relations for a particular Thing
in the $relations
field as I'm only able to specify one inversed side.
Here's what I've come up with so far:
/** @ORMEntity */
class Thing
/**
* @ORMId
* @ORMColumn(type="integer", options="unsigned":true)
* @ORMGeneratedValue
*/
protected $id;
/** @ORMColumn(type="string") */
protected $name;
/**
* @ORMOneToMany(targetEntity="Relation", mappedBy="right")
*/
protected $relations;
/** @ORMEntity */
class Relation
/** @ORMId @ORMColumn(type="string") */
protected $action;
/** @ORMId @ORMManyToOne(targetEntity="Thing") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relations") */
private $right;
php doctrine-orm doctrine
add a comment
|
Let's say I want to implement the following entities in Doctrine:
Thing
represents anything that can perform an action over another Thing
. A Relation
can contain two entities and a description of the action, and its tuple is unique.
Here are some examples of what I'm trying to achieve:
- Hens (thing) lay (action) eggs (thing)
- Water (thing) extinguishes (action) fire (thing)
- Bob (thing) likes (action) apples (thing)
- Bob (thing) drinks (action) water (thing)
As you can see, order matters (it's not the same "Bob likes apples" as "Apples like Bob").
Despite my best efforts, I can't find any proper way to implement this.
I've tried creating a field called $relations
in Thing
tagged as "One-To-Many" and then marking $left
and $right
in Relation
as "Many-To-One". The problem is I can't have two inversed sides for the same owning side (at least AFAIK).
This current implementation neither allows for getting all relations for a particular Thing
in the $relations
field as I'm only able to specify one inversed side.
Here's what I've come up with so far:
/** @ORMEntity */
class Thing
/**
* @ORMId
* @ORMColumn(type="integer", options="unsigned":true)
* @ORMGeneratedValue
*/
protected $id;
/** @ORMColumn(type="string") */
protected $name;
/**
* @ORMOneToMany(targetEntity="Relation", mappedBy="right")
*/
protected $relations;
/** @ORMEntity */
class Relation
/** @ORMId @ORMColumn(type="string") */
protected $action;
/** @ORMId @ORMManyToOne(targetEntity="Thing") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relations") */
private $right;
php doctrine-orm doctrine
Let's say I want to implement the following entities in Doctrine:
Thing
represents anything that can perform an action over another Thing
. A Relation
can contain two entities and a description of the action, and its tuple is unique.
Here are some examples of what I'm trying to achieve:
- Hens (thing) lay (action) eggs (thing)
- Water (thing) extinguishes (action) fire (thing)
- Bob (thing) likes (action) apples (thing)
- Bob (thing) drinks (action) water (thing)
As you can see, order matters (it's not the same "Bob likes apples" as "Apples like Bob").
Despite my best efforts, I can't find any proper way to implement this.
I've tried creating a field called $relations
in Thing
tagged as "One-To-Many" and then marking $left
and $right
in Relation
as "Many-To-One". The problem is I can't have two inversed sides for the same owning side (at least AFAIK).
This current implementation neither allows for getting all relations for a particular Thing
in the $relations
field as I'm only able to specify one inversed side.
Here's what I've come up with so far:
/** @ORMEntity */
class Thing
/**
* @ORMId
* @ORMColumn(type="integer", options="unsigned":true)
* @ORMGeneratedValue
*/
protected $id;
/** @ORMColumn(type="string") */
protected $name;
/**
* @ORMOneToMany(targetEntity="Relation", mappedBy="right")
*/
protected $relations;
/** @ORMEntity */
class Relation
/** @ORMId @ORMColumn(type="string") */
protected $action;
/** @ORMId @ORMManyToOne(targetEntity="Thing") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relations") */
private $right;
php doctrine-orm doctrine
php doctrine-orm doctrine
asked Mar 28 at 21:00
josemmojosemmo
1,7702 gold badges24 silver badges38 bronze badges
1,7702 gold badges24 silver badges38 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
Turns out Doctrine doesn't directly allow for this kind of relation.
The best solution I could came up with was to create two collections in Thing
for the relations instead of one and then defining a method that outputs both:
/** @ORMEntity */
class Thing
// [...]
/** @ORMOneToMany(targetEntity="Relation", mappedBy="left") */
protected $relationsLeft;
/** @ORMOneToMany(targetEntity="Relation", mappedBy="right") */
protected $relationsRight;
public function getRelations()
return new ArrayCollection(array_merge(
$this->relationsLeft->toArray(),
$this->relationsRight->toArray()
));
/** @ORMEntity */
class Relation
// [...]
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsLeft") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsRight") */
private $right;
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406784%2fcustom-many-to-many-relation-in-doctrine%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Turns out Doctrine doesn't directly allow for this kind of relation.
The best solution I could came up with was to create two collections in Thing
for the relations instead of one and then defining a method that outputs both:
/** @ORMEntity */
class Thing
// [...]
/** @ORMOneToMany(targetEntity="Relation", mappedBy="left") */
protected $relationsLeft;
/** @ORMOneToMany(targetEntity="Relation", mappedBy="right") */
protected $relationsRight;
public function getRelations()
return new ArrayCollection(array_merge(
$this->relationsLeft->toArray(),
$this->relationsRight->toArray()
));
/** @ORMEntity */
class Relation
// [...]
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsLeft") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsRight") */
private $right;
add a comment
|
Turns out Doctrine doesn't directly allow for this kind of relation.
The best solution I could came up with was to create two collections in Thing
for the relations instead of one and then defining a method that outputs both:
/** @ORMEntity */
class Thing
// [...]
/** @ORMOneToMany(targetEntity="Relation", mappedBy="left") */
protected $relationsLeft;
/** @ORMOneToMany(targetEntity="Relation", mappedBy="right") */
protected $relationsRight;
public function getRelations()
return new ArrayCollection(array_merge(
$this->relationsLeft->toArray(),
$this->relationsRight->toArray()
));
/** @ORMEntity */
class Relation
// [...]
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsLeft") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsRight") */
private $right;
add a comment
|
Turns out Doctrine doesn't directly allow for this kind of relation.
The best solution I could came up with was to create two collections in Thing
for the relations instead of one and then defining a method that outputs both:
/** @ORMEntity */
class Thing
// [...]
/** @ORMOneToMany(targetEntity="Relation", mappedBy="left") */
protected $relationsLeft;
/** @ORMOneToMany(targetEntity="Relation", mappedBy="right") */
protected $relationsRight;
public function getRelations()
return new ArrayCollection(array_merge(
$this->relationsLeft->toArray(),
$this->relationsRight->toArray()
));
/** @ORMEntity */
class Relation
// [...]
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsLeft") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsRight") */
private $right;
Turns out Doctrine doesn't directly allow for this kind of relation.
The best solution I could came up with was to create two collections in Thing
for the relations instead of one and then defining a method that outputs both:
/** @ORMEntity */
class Thing
// [...]
/** @ORMOneToMany(targetEntity="Relation", mappedBy="left") */
protected $relationsLeft;
/** @ORMOneToMany(targetEntity="Relation", mappedBy="right") */
protected $relationsRight;
public function getRelations()
return new ArrayCollection(array_merge(
$this->relationsLeft->toArray(),
$this->relationsRight->toArray()
));
/** @ORMEntity */
class Relation
// [...]
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsLeft") */
private $left;
/** @ORMId @ORMManyToOne(targetEntity="Thing", inversedBy="relationsRight") */
private $right;
answered Apr 11 at 16:42
josemmojosemmo
1,7702 gold badges24 silver badges38 bronze badges
1,7702 gold badges24 silver badges38 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406784%2fcustom-many-to-many-relation-in-doctrine%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown