Ticket #1452 (closed defect: invalid)

Opened 10 months ago

Last modified 10 months ago

Relations should be automatically loaded when using findById()

Reported by: lsolesen Owned by: jwage
Priority: minor Milestone: 1.0.3
Component: Attributes Version: 1.0.0
Severity: Keywords:
Cc: Has Test: yes
Status: Pending Core Response Has Patch: no

Description

Relations should be automatically loaded when using findById(), but they are not at the moment.

Change History

Changed 10 months ago by lsolesen

/**

class Doctrine_Ticket_1452_TestCase extends Doctrine_UnitTestCase {

public function prepareTables() {

$this->tables[] = 'Model_Product'; parent::prepareTables();

}

public function testFindByIdAutomaticallyLoadsRelationsForInstanceTranslation() {

$name = 'New York'; $description = 'En dansk beskrivelse';

try {

$item = new Model_Product; $item->name = $name; $item->TranslationDK?->description = $description; $item->TranslationEN?->description = 'Some english description'; $item->save();

$reopened = Doctrine::getTable('Model_Product')->findById($item->id); $this->assertEqual($name, $reopened->name); $this->assertEqual($description, $reopened->TranslationDK?->description);

$this->pass();

} catch (Exception $e) {

$this->fail($e->getMessage());

}

}

}

class Model_Product extends Doctrine_Record {

public function setTableDefinition () {

$this->hasColumn('name', 'string', 30); $this->hasColumn('description', 'string', 65555); $this->hasColumn('price', 'integer', 20);

} public function setUp () {

$this->actAs('I18n', array('fields' => array('description')));

}

}

Changed 10 months ago by jwage

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

You need to use findOneById() or find()

Currently if you do findBy{PrimaryKey?} Doctrine isn't smart enough to know to only return 1 record instead of a collection. I think this is a change/enhancement we should make. Can you create another ticket for this?

I added your test in r4955

Note: See TracTickets for help on using tickets.