Bug Report #4157

count_all loses primery key fields if reseting(false)

Added by Andrei Codeator almost 2 years ago. Updated 5 months ago.

Status:New Start date:07/29/2011
Priority:Normal Due 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

Updated by Andrei Codeator almost 2 years ago

Kohana 3.2

Updated by Isaiah DeRose-Wilson over 1 year ago

  • Target version set to v3.2.1

Updated by Lorenzo Pisani 10 months ago

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

Updated by Lorenzo Pisani 10 months 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

Updated by Tomek Rychlik 5 months 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