Bug Report #4157

count_all loses primery key fields if reseting(false)

Added by Andrei Codeator about 3 years ago. Updated over 1 year ago.

Status:NewStart date:07/29/2011
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:Kohana v3.x - Unscheduled
Resolution: Points:1

Description

Kohana_ORM 1488 loozes primary key select
If I do
foreach($selects as $select) {
$this->_db_pending[] = $select;
}
Instead $this->_db_pending += $selects; Everything works fine.

For example:

$oEntity = ORM::factory('Entity')
->with('entityfriends')
->where('entityfriends.id', 'in', DB::expr('(1,2,3)'))
->order_by('time_end', 'DESC');

$count_all = $oEntity->reset(false)->count_all();

// THAN IF I WILL TRY TO ITERATE THROUGH ENTITY AND FIND ENTITY FRIENDS THEY WILL BE UNLOADED

foreach($oEntity->find_all() as $entity) {
var_dump($entity->entityfriends->loaded());
// WILL BE FALSE, BUT IF COMMENT OUT COUNT_ALL IT WILL BE TRUE, BECAUSE WE LOOSE id (first one) SELECT ON Kohana_ORM:1488
}

History

#1 Updated by Andrei Codeator about 3 years ago

Kohana 3.2

#2 Updated by Isaiah DeRose-Wilson over 2 years ago

  • Target version set to v3.2.1

#3 Updated by Lorenzo Pisani almost 2 years ago

  • Subject changed from count_all loozes primery key fields if reseting(false) to count_all loses primery key fields if reseting(false)

#4 Updated by Lorenzo Pisani almost 2 years ago

  • Target version changed from v3.2.1 to Unscheduled

Sorry but I can't figure out how to reproduce this issue. Could you give me your database schema for the two tables? Moving to unscheduled for now so we can release 3.2.1

#5 Updated by Tomek Rychlik over 1 year ago

Its true, I have the same problem.

I fixed it, by preservation keys:

        foreach ($this->_db_pending as $key => $method)
        {
            if ($method['name'] == 'select')
            {
                $selects[*$key*] = $method;
                unset($this->_db_pending[$key]);
            }
        }

Also available in: Atom PDF