0 votes

Hi,

how the title says I am trying to create a "One-To-Many, Bidirectional with a Join Table" relationships with skipper.

The use case is:
I need a contact with many phone numbers but the phone number should be only connected to one contact.

so...
on the Contact Entity I will like to have a Phone numbers collection
on the PhoneNumber Entity I will like to have an Contact Entity (not a Contact collection)

and...
the inverse side should be the phone number and contact should be the owner side.

Thank you,
Best

in Solved by (120 points)
recategorized by

1 Answer

+1 vote

Hi, I believe that for the use case you described is bidirectional connection without join table sufficient solution.

But in case you need a join table, simply create the connection by using Many-to-Many association tool and then limit one side of MN to one-to-one. This will create configuration you need (and this is also how doctrine implements it as you can find in documentation)

by Skipper developer (141k points)

Hi,

thank you very much for the fast answer.

So I will like to have the join table the problem is that I can not find in skipper the option to "limit one side of MN to one-to-one"

enter image description here

Thanks again,
Best

You need to click on one of the association lines, not on MN table. After that you will be able to configure each direction separately.

Hmm... interesting that's exactly what I did. I have "click on one of the association lines" and the previous screen shot is where I land :/

enter image description here

p.s It seams I have the newer skipper version 3.2.7.1338

You're right. Obviously what I described was some previous behavior which is currently replaced by what you found.

But it seems that there is missing some "Is-unique" direction option in this dialog. So to be able to achieve what you need to do please open MN tableenter image description here

And check UQ on the reference field you need to be one-to-one. By selecting field unique, you're telling to Doctrine (and Database) that only one such reference should exist.

Hi again :)

Yes exactly this is what I did and it was working good but here my problem starts after exporting the MN from skipper in have in my both Entities @ORM\ManyToMany (ok the good part is that the unique one is also marked as unique)

enter image description here

enter image description here

but after running orm:generate-entities ... --generate-annotations=true both sides (in my case contacts and personalData) are \Doctrine\Common\Collections\ArrayCollection() and this is not really true because on the unique side (in my case contacts) the class proprety should be an single Entity and not a Collection.

Thank you again for the help!
Best

Ok. But are you sure that this is not limitation of doctrine? Are you able to write schema manually to get desired output? If so, can you paste it here?

What do you mean with "write schema manually" ?
thx!
Best

I mean if you know how to model it without Skipper. By writing pure schema.xml or schema.php directly in Doctrine schema files.