loadBy() public method

Load record by condition.
public loadBy ( mixed $field, mixed $value )
$field mixed
$value mixed
Ejemplo n.º 1
0
 public function testLoadBy()
 {
     $a = ['types' => [['date' => '2013-02-20']]];
     $this->setDB($a);
     $db = new Persistence_SQL($this->db->connection);
     $m = new Model($db, ['table' => 'types']);
     $m->addField('date', ['type' => 'date', 'dateTimeClass' => '\\atk4\\data\\tests\\MyDate']);
     $m->loadAny();
     $d = $m['date'];
     $m->unload();
     $m->loadBy('date', $d)->unload();
     $m->addCondition('date', $d)->loadAny();
 }
Ejemplo n.º 2
0
 public function testDoubleReverseJoin()
 {
     $a = ['user' => [10 => ['id' => 10, 'name' => 'John 2', 'contact_id' => 100], 20 => ['id' => 20, 'name' => 'Peter', 'contact_id' => 100], 30 => ['id' => 30, 'name' => 'XX', 'contact_id' => 200], 40 => ['id' => 40, 'name' => 'YYY', 'contact_id' => 300]], 'contact' => [100 => ['id' => 100, 'contact_phone' => '+555', 'country_id' => 1], 200 => ['id' => 200, 'contact_phone' => '+999', 'country_id' => 2], 300 => ['id' => 300, 'contact_phone' => '+777', 'country_id' => 5]], 'country' => [1 => ['id' => 1, 'name' => 'UK'], 2 => ['id' => 2, 'name' => 'US'], 3 => ['id' => 3, 'name' => 'India']]];
     $this->setDB($a);
     $db = new Persistence_SQL($this->db->connection);
     $m_u = new Model($db, 'user');
     $m_u->addField('contact_id');
     $m_u->addField('name');
     $j = $m_u->join('contact');
     $j->addField('contact_phone');
     $c = $j->join('country');
     $c->addField('country_name', ['actual' => 'name']);
     $m_u->load(10);
     $m_u->delete();
     $m_u->loadBy('country_name', 'US');
     $this->assertEquals(30, $m_u->id);
     $this->assertEquals(['user' => [20 => ['id' => 20, 'name' => 'Peter', 'contact_id' => 100], 30 => ['id' => 30, 'name' => 'XX', 'contact_id' => 200], 40 => ['id' => 40, 'name' => 'YYY', 'contact_id' => 300]], 'contact' => [200 => ['id' => 200, 'contact_phone' => '+999', 'country_id' => 2], 300 => ['id' => 300, 'contact_phone' => '+777', 'country_id' => 5]], 'country' => [2 => ['id' => 2, 'name' => 'US'], 3 => ['id' => 3, 'name' => 'India']]], $this->getDB());
 }
Ejemplo n.º 3
0
 public function testActual()
 {
     $db = new Persistence_SQL($this->db->connection);
     $a = ['user' => [1 => ['id' => 1, 'name' => 'John', 'surname' => 'Smith']]];
     $this->setDB($a);
     $m = new Model($db, 'user');
     $m->addField('first_name', ['actual' => 'name']);
     $m->addField('surname');
     $m->insert(['first_name' => 'Peter', 'surname' => 'qq']);
     $m->loadBy('first_name', 'John');
     $this->assertEquals('John', $m['first_name']);
     $d = $m->export();
     $this->assertEquals('John', $d[0]['first_name']);
     $a = ['user' => [1 => ['id' => 1, 'name' => 'John', 'surname' => 'Smith'], 2 => ['id' => 2, 'name' => 'Peter', 'surname' => 'qq']]];
     $this->assertEquals($a, $this->getDB());
     $m['first_name'] = 'Scott';
     $m->save();
     $a = ['user' => [1 => ['id' => 1, 'name' => 'Scott', 'surname' => 'Smith'], 2 => ['id' => 2, 'name' => 'Peter', 'surname' => 'qq']]];
     $this->assertEquals($a, $this->getDB());
 }