Doctrine ORM One to One relationship

  Рет қаралды 4,224

Gary Clarke

Gary Clarke

Күн бұрын

Пікірлер: 6
@9Elix9
@9Elix9 2 жыл бұрын
Hello Gary, love your videos. I have question regarding OneToOne relation. (I will explain my setup) I have TableA and TableB. TableA is my primary table, TableB is my additonal table. OneToOne relation is done like this: in table A I have property tableB which doesn't have JoinColumn option. (I do not want to have TableB's ID stored in TableA) Via tableB property I am accessing to TableB's properties. TableB have tableA(unique key) property which has JoinCoulmn option, and in TableB I want to store TableA's ID. Problem occurs when I want to update data eg. I want to send PUT request and in that request I am sending data for TableA and for TableB (via tableA property). I got unique constraint violations, because it tries to POST data (which I am sending via request) even though it has the same data written into the data base. I tried to manage this error, but later I got "entity not managed" error. So everything else works, just PUT/UPDATE request is causing problems. I also tried your Customer-Cart variation, then it will do the data update but there is no connection between theese two tables, my customer_id in cart table is NULL. Every other time I send update data for the same ID of Customer it creates new Cart without connection to Customer. Best wishes.
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
It's a good question. I'll try to find an example and come back to you
@ricohumme4328
@ricohumme4328 3 жыл бұрын
Hi Gary, what I am missing in this video is the why should you use / not use one to one relations. I believe this is a key differentiator between one to one and many to one relations. Other than that, good info on this topic.
@GaryClarkeTech
@GaryClarkeTech 3 жыл бұрын
Hi Rico...good point, I should make the distinction clear. I use one to ones rarely because the question I always end up asking myself is 'Why create a separate table in the first place? Can't I just add extra fields to the parent?' The answer is usually yes. I will use one to ones where the extra fields are going to be applicable to less than half of the records and I want to avoid redundant / empty fields in the majority of records. One to many is a lot simpler because if you need it, you need it; it's not optional.
@hrefamid9563
@hrefamid9563 2 жыл бұрын
How does cascade persiste and remove work on a OneToOne relation? On which side can you or do you have to specify it? I’m wondering the same on a ManyToMany, I think I’ve figured it out for a ManyToOne 🤔
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
I wouldn't do this with a many to many..think about possible consequences..you might remove records that have a relationship with others.
Doctrine ORM Many to Many Relationship
10:26
Gary Clarke
Рет қаралды 7 М.
No BS SOLID Principles
51:06
Gary Clarke
Рет қаралды 3 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Doctrine ORM One to Many Relationship (bidirectional)
16:04
Gary Clarke
Рет қаралды 17 М.
Doctrine ORM - PHP Entities & Data Mapper Pattern - Full PHP 8 Tutorial
26:18
Symfony tutorial: Embed a Collection of Forms
1:26:27
OverSeas Media
Рет қаралды 32 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 299 М.
7 Database Design Mistakes to Avoid (With Solutions)
11:29
Database Star
Рет қаралды 100 М.
10 Signs Your Software Project Is Heading For FAILURE
17:59
Continuous Delivery
Рет қаралды 46 М.
I just tried o3-mini
6:31
ThePrimeTime
Рет қаралды 235 М.
Laravel Microservice - Project Setup and Getting Started
13:31
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН