Ticket #923 (closed defect: invalid)

Opened 15 months ago

Last modified 15 months ago

The result isn't correct if the table doesn't contain a primary key

Reported by: Garfield-fr Owned by: jwage
Priority: major Milestone: 0.11.0
Component: Attributes Version: 0.10.0
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description

my schema:

Diagnostics:
  tableName:              diagnostics
  columns:
    id_type:
      type:   integer(4)
    id:
      type:   integer(4)
    diagnostic_id:
      type:   integer(4)
    operator_id:
      type:   integer(4)
    timestamp:
      type:   timestamp
    extra_info:
      type:   string(200)
    validation_id:
      type:   integer(4)
    error:
      type:   integer(1)

  relations:
    Users:
      local:  operator_id
      foreign:  user_id

DQL:

$this->date_start = '2007-01-30 00:00:00';
$this->date_end = '2007-01-30 23:59:59';

$this->result = Doctrine_Query::create()
->select('d.*, u.*')
->from('Diagnostics d')
->where('d.timestamp >= ? AND d.timestamp <= ?', array($this->date_start, $this->date_end))
->leftJoin('d.Users u')
->addWhere('d.id_type = ?', array('101'))
->orderBy('d.timestamp')
->limit(20)
->offset(0)
->execute();

Doctrine SQL:

SELECT a.* FROM (SELECT d.id AS d__id, d.id_type AS d__id_type, d.diagnostic_id AS d__diagnostic_id, d.operator_id AS d__operator_id, d.timestamp AS d__timestamp, d.extra_info AS d__extra_info, d.validation_id AS d__validation_id, d.error AS d__error, u.user_id AS u__user_id, u.user_name AS u__user_name, u.first_name AS u__first_name, u.last_name AS u__last_name, u.last_login_time AS u__last_login_time, u.user_type AS u__user_type, u.active AS u__active FROM diagnostics d LEFT JOIN users u ON d.operator_id = u.user_id WHERE (d.timestamp >= ? AND d.timestamp <= ?) AND d.id_type = ? ORDER BY d.timestamp) a WHERE ROWNUM <= 20 - (2007-01-30 00:00:00, 2007-01-30 23:59:59, 101 )

--> Result: 13 records

Oracle SQL:

SELECT a.* FROM (SELECT d.id AS d__id, d.id_type AS d__id_type, d.diagnostic_id AS d__diagnostic_id, d.operator_id AS d__operator_id, d.timestamp AS d__timestamp, d.extra_info AS d__extra_info, d.validation_id AS d__validation_id, d.error AS d__error, u.user_id AS u__user_id, u.user_name AS u__user_name, u.first_name AS u__first_name, u.last_name AS u__last_name, u.last_login_time AS u__last_login_time, u.user_type AS u__user_type, u.active AS u__active FROM diagnostics d LEFT JOIN users u ON d.operator_id = u.user_id WHERE (d.timestamp >= to_date('2007-01-30 00:00:00', 'YYYY-MM-DD HH24:MI:SS') AND d.timestamp <= to_date('2007-01-30 23:59:59','YYYY-MM-DD HH24:MI:SS')) AND d.id_type = 101 ORDER BY d.timestamp) a WHERE ROWNUM <= 20

--> Result: 20 records

Change History

Changed 15 months ago by jwage

  • milestone changed from 0.10.4 to 0.10.5

Changed 15 months ago by jwage

  • status changed from new to closed
  • resolution set to invalid

Your model either needs a primary key or you need to change the way you work with it. Doctrine requires their be a primary key in order for Doctrine to hydrate the data.

Changed 15 months ago by Garfield-fr

  • status changed from closed to reopened
  • resolution invalid deleted

I can not change the model because it is from a library product. This is the real table into my database.

Why should we define a primary key ?

My original query (oracle sql) work prefectly.

Do you have a solution for me ?

I would like to use doctrine, but it does not work

Changed 15 months ago by Garfield-fr

Why do you have changed my testcase ?

This is a real problem. The ORM don't work with my case and for me is a big problem.

Changed 15 months ago by Garfield-fr

In revision #4154, you are changed the id but into my base, i have this case. This id is a foreignkey to another record (not unique). The pattern of our supplier is not correct but there are in this database

Changed 15 months ago by romanb

  • status changed from reopened to closed
  • resolution set to invalid

Because it is impossible to hydrate correctly without an identifier (primary key). Execute the SQL, look at the result set and tell us how doctrine can differentiate what data in what row belongs to which object. We're open to suggestions. So as long as we have no solution to that you simply can't model that table's contents as Records. What about the diagnostic_id ? Isnt that the unique identifier of a Diagnostic? If so, mark this field as the pk in the model and you're fine.

Maybe it needs to be made more clear in the manual: All Record classes need an identifier (a primary key). A Record needs to have a unique identity!

Changed 15 months ago by Garfield-fr

Romanb, all fields aren't unique.

I have tested to make PM on id and diagnostic_id, but a have an pdo error because i don't have PK on my table.

Example of diagnostic_id:
17545 => Invalid Header
17456 => Authority deleted

I can not change the database.

I will test this case with Propel :(

Note: See TracTickets for help on using tickets.