Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Overlapped composite foreign keys and no expected related object
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Angel B.A.  
View profile  
 More options Nov 8 2012, 9:20 am
From: "Angel B.A." <ank...@gmail.com>
Date: Thu, 8 Nov 2012 06:20:09 -0800 (PST)
Local: Thurs, Nov 8 2012 9:20 am
Subject: Overlapped composite foreign keys and no expected related object

Hello:

I think there is no information in nowhere about this issue, so I publish
it here to discuss:

Suppose a record from a table with some field(s), part of a composite
foreign key, having null value while the others fields of the composite
foreign key having correct values. In this case Doctrine returnes a related
object instead of ... nothing. I think it's an error because this situation
can appear when a field belongs to more than one composite foreign key.

An fictious example to explain better:

Imagine this tables (* marks the primary key),

Person:

*id_person
name
surname
id_country
id_city
id_district

Country
*id_country
name

City
*id_country
*id_city
name

District
*id_country
*id_city
*id_district
name

We want district optional to Persons, so :

Country:
id_country  name
34              Spain
52             México
...             ...

City:
id_country  id_city name
34               27       Lugo
34               32       Ourense
52               27       Cuernavaca
53               15       Aguascalientes
...               ...          ....

District
id_country    id_city    id_district  name
34                  27            1           Casco histórico
34                  27            2           Murallas
52                  ...            ...           ...
52                  ...            ...           ...

If we have a 'person' record like this:

id_person: 45
name: Margaret
surname: Drinkwater
id_country: 34
id_city: 27
id_district: null

then  findBy(45)  returns the object "Margaret Drinkwater" with related
objects "Country:  Spain (34)" correct!, "City: Lugo (34 27)" correct
too!... and "District: Murallas (34  27  2)" wtf!!

It's a fictious example but we find this behavior in a real environment and
gives us a headache for a long time :-)

Is possible an improvement in this sense?

Diving in source code we find that error (?) relies in createEntity method
of UnitOfWork class.

Excuse my criminal English :-) ... and thanks in advance


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jasper N. Brouwer  
View profile  
 More options Nov 8 2012, 10:33 am
From: "Jasper N. Brouwer" <jas...@nerdsweide.nl>
Date: Thu, 8 Nov 2012 16:33:22 +0100
Local: Thurs, Nov 8 2012 10:33 am
Subject: Re: [doctrine-user] Overlapped composite foreign keys and no expected related object
Can you post your entity-mapping information?

--
Jasper N. Brouwer

On 08-11-2012, at 15:20, Angel B.A. <ank...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Angel B.A.  
View profile  
 More options Nov 9 2012, 2:33 am
From: "Angel B.A." <ank...@gmail.com>
Date: Thu, 8 Nov 2012 23:33:17 -0800 (PST)
Local: Fri, Nov 9 2012 2:33 am
Subject: Re: [doctrine-user] Overlapped composite foreign keys and no expected related object

In the real situation we have this:

namespace Aplicacion\ExemploBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Aplicacion\ExemploBundle\Entity\Persoa
 *
 * @ORM\Table(name="PERSOA")
 * @ORM\Entity
 */
class Persoa
{
    /**
     * @var string $nif
     *
     * @ORM\Column(name="NIF", type="string", length=9, nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     */
    private $nif;

    /**
     * @var string $apelido1
     *
     * @ORM\Column(name="APELIDO1", type="string", length=25, nullable=true)
     */
    private $apelido1;

    /**
     * @var string $apelido2
     *
     * @ORM\Column(name="APELIDO2", type="string", length=25, nullable=true)
     */
    private $apelido2;

    /**
     * @var string $nome
     *
     * @ORM\Column(name="NOME", type="string", length=20, nullable=false)
     */
     private $nome;

    /**
     * @var Provincia    
     *
     * @ORM\ManyToOne(targetEntity="Plantilla\ComunBundle\Entity\Provincia")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="COD_PROVINCIA",
referencedColumnName="COD_PROVINCIA")
     * })
     */
     private $provincia;

     /**
     * @var concello    
     *
     * @ORM\ManyToOne(targetEntity="Plantilla\ComunBundle\Entity\Concello")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="COD_PROVINCIA",
referencedColumnName="COD_PROVINCIA"),@ORM\JoinColumn(name="COD_CONCELLO",
referencedColumnName="COD_CONCELLO")
     * })
     */
     private $concello;

     /**
     * @var parroquia
     *
      *
@ORM\ManyToOne(targetEntity="Plantilla\ComunBundle\Entity\Parroquia")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="COD_PROVINCIA",
referencedColumnName="COD_PROVINCIA"),@ORM\JoinColumn(name="COD_CONCELLO",
referencedColumnName="COD_CONCELLO"),@ORM\JoinColumn(name="COD_PARROQUIA",
referencedColumnName="COD_PARROQUIA")
     * })
     */
     private $parroquia;    

     /**
     * @var lugar
     *
     * @ORM\ManyToOne(targetEntity="Plantilla\ComunBundle\Entity\Lugar")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="COD_PROVINCIA",
referencedColumnName="COD_PROVINCIA"),@ORM\JoinColumn(name="COD_CONCELLO",
referencedColumnName="COD_CONCELLO"),@ORM\JoinColumn(name="COD_PARROQUIA",
referencedColumnName="COD_PARROQUIA"),@ORM\JoinColumn(name="COD_LUGAR",
referencedColumnName="COD_LUGAR")
     * })
     */
     private $lugar;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jasper N. Brouwer  
View profile  
 More options Nov 9 2012, 3:54 am
From: "Jasper N. Brouwer" <jas...@nerdsweide.nl>
Date: Fri, 9 Nov 2012 09:53:49 +0100
Local: Fri, Nov 9 2012 3:53 am
Subject: Re: [doctrine-user] Overlapped composite foreign keys and no expected related object
I've never seen an association like this, using 3 @joinColumns. I don't think this is supported (but I could be wrong).

Why don't you try the following setup:

    Person <- ManyToOne -> City
    Person <- ManyToOne -> District

    Country <- OneToMany -> City

    City <- OneToMany -> Person
    City <- ManyToOne -> Country
    City <- OneToMany -> District

    District <- ManyToOne -> Person
    District <- ManyToOne -> City

So a District belongs to a City, and a City belongs to a Country.
A person has either a District or a City (always one of these, but never both). You can enforce this in the entity code.

In Person you can make the following convenience functions:

getCity()    : If Person has related City, return that city. Else return the City of the related District.
getCountry() : If Person has related City, return Country of that City. Else return the Country of the City of the related District.

--
Jasper N. Brouwer

On 09-11-2012, at 08:33, Angel B.A. <ank...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Angel B.A.  
View profile  
 More options Nov 9 2012, 8:33 am
From: "Angel B.A." <ank...@gmail.com>
Date: Fri, 9 Nov 2012 05:33:10 -0800 (PST)
Local: Fri, Nov 9 2012 8:33 am
Subject: Re: [doctrine-user] Overlapped composite foreign keys and no expected related object

Thanks for your reply.

The associations in the real code posted in previous message works
perfectly when I persists the related objects, only fails recovering the
objects from the DB because Doctrine treats a composite foreign key as
valid even if  the values are incomplete, so it takes any object thats
satisfies this "partial" foreign key. I think this should trigger an error
or ignore the incomplete values, at the very least.

However, from the beginning I suspect that I am in a conceptual error, but
I don't find it (and it isn't the hierarchichal relations among the
Location entities).  Furthermore, it's difficult to explain the work
context who takes us to this association schema (Location tables are shared
among different projects and we are creating this as a part of an
"applications template" that will contain "Location facilities" for the
programmers).

So I will take your suggestions as a point to rethink my approach. But I
still think that Doctrine should, at the very least, ignore the "incomplete
values" in a composite foreign key (or create a warn message) instead of
returning some object.

Thank you very much for your time!

El viernes, 9 de noviembre de 2012 09:54:01 UTC+1, Jàπ (Jasper N. Brouwer)
escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jasper N. Brouwer  
View profile  
 More options Nov 9 2012, 9:07 am
From: "Jasper N. Brouwer" <jas...@nerdsweide.nl>
Date: Fri, 9 Nov 2012 15:06:54 +0100
Local: Fri, Nov 9 2012 9:06 am
Subject: Re: [doctrine-user] Overlapped composite foreign keys and no expected related object
I understand that if those "location entities" are a shared part of many projects, it can be hard/time-consuming to refactor this.

But I'm still not sure Doctrine can do what you want it to do.
Do you have the Doctrine console running? If so, could you do a:
    $ doctrine orm:validate-schema

This way we can make sure Doctrine understands what you want ;)

--
Jasper N. Brouwer

On 09-11-2012, at 14:33, Angel B.A. <ank...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Angel B.A.  
View profile  
 More options Nov 21 2012, 9:34 am
From: "Angel B.A." <ank...@gmail.com>
Date: Wed, 21 Nov 2012 06:34:06 -0800 (PST)
Local: Wed, Nov 21 2012 9:34 am
Subject: Re: [doctrine-user] Overlapped composite foreign keys and no expected related object

(Excuse me, but I couldn't return to this theme for a lot of days)

This is not the point, the mappings are OK (perhaps the concept I use it
isn't :-)

Previous to write in this group I dived deep in the doctrine code and I
found that there is no check to the field's number of a composite foreign
key when it builds the related object. It iterates all the fields and if
ALL are null, then returns no object. But if ONE is not null it starts to
build the SQL query, with no check about the number of conditions to build
(that would be exactly the same number as fields number in the composite
key, not less).

At the end, the question is:

Is correct to reutilize a field in two composite foreign keys?

If it is, then doctrine should return a null object if at least one field
of the composite foreign key is null.

(For reference, the doctrine code is in createEntity function in  
doctrine\lib\Doctrine\ORM\UnitOfWork.php )

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »