[DDC-2470] Sql Server error in createQuery using ORDER BY and setMaxResults Created: 24/May/13  Updated: 24/May/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.4, 2.3.4
Fix Version/s: None
Security Level: All

Type: Bug Priority: Blocker
Reporter: Jonnatan Oyarzún Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: dql, sqlserver
Environment:

Windows 7, Apache 2 (xampp 1.8.1), PHP 5.4.7, Symfony 2.2.1


Attachments: PNG File BD.png    

 Description   

When executing

$query = $em->createQuery(
'SELECT m.nombre, m.fechainicio, m.fechafin FROM Bundle:Medicion m
JOIN m.estudio e
JOIN e.cliente c
JOIN c.usuarios u
WHERE u.id = :id
ORDER BY m.fechainicio DESC')
->setMaxResults(12)
>setParameter('id', $user>getId());

Get the following error:

An exception occurred while executing 'SELECT * FROM (SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2, ROW_NUMBER() OVER (ORDER BY FECHAINICIO1 DESC) AS doctrine_rownum FROM MEDICION m0_ WITH (NOLOCK) INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID WHERE u3_.ID = ?) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 12' with params [2]:

SQLSTATE[42S22]: [Microsoft][SQL Server Native Client 11.0][SQL Server]El nombre de columna 'FECHAINICIO1' no es válido.

Attached the BD model

regards
Jonnatan Oyarzún






[DDC-2469] SQLite handling for ENUM-Fields Created: 24/May/13  Updated: 24/May/13  Resolved: 24/May/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Andy Rosslau Assignee: Marco Pivetta
Resolution: Invalid Votes: 0
Labels: query, schematool, sqlite


 Description   

SQLite doesn't support ENUMS!

But when I try create the schema of the following Entity Doctrine generates this "CREATE TABLE" - Statement:

CREATE TABLE Entity ([...] NOT NULL, taxation ENUM('incl', 'excl'), maxNumbe[...]
class Entity {
...

    /**
     * @var string
     *
     * @ORM\Column(type="string", columnDefinition="ENUM('incl', 'excl')")
     */
    private $taxation = self::TAXATION_INCL;

...
}

Produces this error:

SQLSTATE[HY000]: General error: 1 near "'incl'": syntax error'



 Comments   
Comment by Marco Pivetta [ 24/May/13 ]

Usage of

columnDefinition

in annotations or generally metadata mappings is all about vendor specific syntax. `columnDefinition` is designed to allow overriding the default ORM column generated DDL to build vendor specific syntax/types, therefore the issue is invalid





[DDC-2468] xml schema incomplete Created: 23/May/13  Updated: 23/May/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: David Buchmann Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

while writing the schema for phpcr-odm i noticed that the orm schema seems to miss some things. not sure if they are just missing in the schema but supported by the xml driver or if the xml driver also misses those:

cascade-type is missing

<xs:element name="cascade-detach" type="phpcr:emptyType" minOccurs="0"/>

lifecycle-callback-type is missing a bunch of callbacks:

<xs:enumeration value="onFlush"/>
<xs:enumeration value="postFlush"/>
<xs:enumeration value="onClear"/>
<xs:enumeration value="loadClassMetadata"/>






[DDC-2467] Incorrect work with default values, indexes, autoincrement (patch attached) Created: 23/May/13  Updated: 23/May/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers, ORM, Tools
Affects Version/s: 2.3.4
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: And Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Attachments: Text File ORM.patch    

 Description   

If you use in your MySQL database default values, indexes or string primary key, you get incorrect mapping by mapping generator. For get it - just use in database one or more from listed abilities, generate mapping for that and then try to dump-sql with schema-tool:update.

Hope you fix it. Tnx!



 Comments   
Comment by Marco Pivetta [ 23/May/13 ]

Marked as minor improvement - thank you for the patch!





[DDC-2466] [GH-676] Update UnitOfWork.php Created: 22/May/13  Updated: 22/May/13  Resolved: 22/May/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Marco Pivetta
Resolution: Won't Fix Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of Kynareth62:

Url: https://github.com/doctrine/doctrine2/pull/676

Message:

Here, if a field (type date or datetime) is defined as id, I have an error because it's an object and not a string...

Can you please fix this bug ? Thank you.



 Comments   
Comment by Doctrine Bot [ 22/May/13 ]

A related Github Pull-Request [GH-676] was closed:
https://github.com/doctrine/doctrine2/pull/676

Comment by Marco Pivetta [ 22/May/13 ]

Related: DDC-1209, DDC-1780





[DDC-2465] ProxyClass load, and empty ids Created: 21/May/13  Updated: 22/May/13  Resolved: 21/May/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3.4
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Gabriele Tondi Assignee: Marco Pivetta
Resolution: Invalid Votes: 0
Labels: None
Environment:

Osx



 Description   

If you have lazy association (example many-to-one) that have empty id (for empty i mean empty string and not null) you (correctly) get EntityNotFoundException.

But i'm working with a system that sometimes put an empty string instead of null in fk fields.

So i've add this little snipped of code __load method in $_proxyClassTemplate, ProxyFactory:

// GT, 2013-05-21 If all identifier are empty you not need to try load

        if (is_array($this->_identifier)) {
            $isEmpty = true;
            foreach($this->_identifier as $iK => $iV) {
                if (!empty($iV))
                    $isEmpty = false;
            }

            if ($isEmpty)
                return;
        }
        // END GT EDIT


 Comments   
Comment by Marco Pivetta [ 21/May/13 ]

What does `$this->_identifier` contain in your failing case?

Comment by Gabriele Tondi [ 21/May/13 ]

It contains for example

array(
[id] =>
);

Because on db you find an empty string and not a null value.

Comment by Marco Pivetta [ 21/May/13 ]

If I get it correctly, you are using empty strings to emulate NULL references, which is invalid in SQL ( I've explained it extensively at http://stackoverflow.com/questions/15502408/doctrine-2-use-default-0-values-instead-of-null-for-relation/15511715#15511715 )

Is this what you are doing? Because for any identifier that is not NULL an attempt to load it should be run, regardless of its content.

Comment by Gabriele Tondi [ 21/May/13 ]

That's not me

It's the system by which i'm sharing the db.
It uses MyIsam engine with no fk or index, so i've found this way to skip load when on db i've empty strings.

Are there other (maybe cleaner) ways?

Thanks,
Gabriele

Comment by Marco Pivetta [ 21/May/13 ]

No, the only correct way to handle this is to set NULL values for the association meta-columns. Marking as invalid

Comment by Gabriele Tondi [ 21/May/13 ]

I can't find doc about it: https://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html?highlight=column#annref-column

Can you give an example?

Comment by Marco Pivetta [ 21/May/13 ]

`$this->someAssociation = NULL;`. That's basically what I mean.

Comment by Gabriele Tondi [ 22/May/13 ]

Mmm, didn't understand.

Anyway, we've tried to fix the old Delphi Monster witch store empty strings instead of nulls... with no results.

So, here is my workaround, maybe this can be useful for other developers who will be in troubles in the future..

In "UnitOfWork" class, public method "createEntity".

[...]

UnitOfWork.php
 
// TODO: Is this even computed right in all cases of composite keys?
                    foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) {
                        $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null;

                        // START-EDIT

                        // GT: our moas store empty string instead of null in fk columns.
                        // So, let's check and handle it as null!

                        if (empty($joinColumnValue))
                            $joinColumnValue = null;

                        // END-EDIT

                        if ($joinColumnValue !== null) {
                            if ($targetClass->containsForeignIdentifier) {
                                $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue;
                            } else {
                                $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
                            }
                        }
                    }

[...]

Regards,
Gabriele

Comment by Marco Pivetta [ 22/May/13 ]

Gabriele Tondi the ORM does not deal with such architectures (nor with generally invalid usage of RDBMS systems). The only acceptable solution in ORM is with correct NULL values, as it should be, so this patch is invalid.





[DDC-2464] useless index for the middle table of many-to-many relationship Created: 21/May/13  Updated: 21/May/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: scourgen Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: ddl, schematool


 Description   

I have entity A and B, the relationship between A and B is many-to-many. which means Doctrine2 will generate a middle table called AB for me.

entity A:

class Station {
    /**
     * @ORM\ManyToMany(targetEntity="Fun", mappedBy="stations")
     */
    protected $funs;
}

entity B:

class Fun {
    /**
     * @ORM\ManyToMany(targetEntity="Station", inversedBy="funs")
     * @ORM\JoinTable(name="stations_have_funs")
     */
    protected $stations;
}

the schema of middle table stations_have_funs:

CREATE TABLE `stations_have_funs` (
  `fun_id` int(11) NOT NULL,
  `station_id` int(11) NOT NULL,
  PRIMARY KEY (`fun_id`,`station_id`),
  KEY `IDX_45C921911CA4BE49` (`fun_id`),
  KEY `IDX_45C9219121BDB235` (`station_id`),
  CONSTRAINT `FK_45C921911CA4BE49` FOREIGN KEY (`fun_id`) REFERENCES `funs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_45C9219121BDB235` FOREIGN KEY (`station_id`) REFERENCES `stations` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

I noticed that there are 2 useless index(fun_id and station_id). Since fun_id and station_id are the primary key of this table. Do we really need 2 extra/duplicated index ?






[DDC-2463] [GH-675] Implementation for 'IsNot'-Comparison Created: 20/May/13  Updated: 20/May/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of pmattmann:

Url: https://github.com/doctrine/doctrine2/pull/675

Message:

See PR (https://github.com/doctrine/collections/pull/11)

This is the required implementation for 'IsNotNull'-Filters in Collection-Filtering.






[DDC-2462] [GH-674] Shortcut for force Created: 20/May/13  Updated: 20/May/13

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of TorbenBr:

Url: https://github.com/doctrine/doctrine2/pull/674

Message:






Generated at Fri May 24 23:54:16 UTC 2013 using JIRA 5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5.