Ejemplo n.º 1
0
 public function modelRelationMap()
 {
     return ['product' => array('type' => 'hasOne', 'class' => Product::className(), 'link' => array('productCode' => 'productCode'), 'allToArray' => true), 'order' => array('type' => 'belongsTo', 'class' => Order::className(), 'link' => array('id' => 'orderId')), 'customer' => array('type' => 'belongsTo', 'class' => Customer::className(), 'link' => array('id' => 'customerId'))];
 }
 /**
  * Test active record array deleteFull() where canDelete has been set to false
  *
  * @expectedException        \fangface\db\Exception
  * @expectedExceptionMessage Attempting to delete Item(s) model flagged as not deletable
  */
 function testActiveRecordDeleteFullOnNonCanDeleteArrayFails()
 {
     $client = Client::findOne(1);
     $this->assertInstanceOf(Client::className(), $client);
     $this->setService('client', $client);
     $customerId = $this->createTestCustomerAndOrder($client->clientCode);
     $this->assertTrue($customerId !== false && $customerId > 0);
     $this->checkBaseCounts('full', $client->clientCode);
     $customer = Customer::findOne($customerId);
     $this->assertInstanceOf(Customer::className(), $customer);
     $customer->orders[1]->items->setCanDelete(false);
     $customer->orders[1]->items->deleteFull();
 }
Ejemplo n.º 3
0
 public function modelRelationMap()
 {
     return ['country' => array('type' => 'hasOne', 'class' => Country::className(), 'link' => array('countryCode' => 'countryCode'), 'readOnly' => true, 'canDelete' => false, 'allToArray' => true), 'customer' => array('type' => 'belongsTo', 'class' => Customer::className(), 'link' => array('id' => 'customerId'))];
 }
Ejemplo n.º 4
0
 public function modelRelationMap()
 {
     return ['items' => array('type' => 'hasMany', 'class' => Item::className(), 'link' => array('orderId' => 'id'), 'onSaveAll' => ActiveRecord::SAVE_CASCADE, 'onDeleteFull' => ActiveRecord::DELETE_CASCADE, 'autoLinkType' => ActiveRecord::LINK_FROM_PARENT_MAINT, 'allToArray' => true, 'autoLink' => array('fromParent' => array('orderId' => 'id', 'customerId' => 'customerId'))), 'customer' => array('type' => 'belongsTo', 'class' => Customer::className(), 'link' => array('id' => 'customerId'))];
 }
Ejemplo n.º 5
0
 /**
  * Amend customer id at top level of a relation and test that a push()
  * request forces relations that have customerId set are updated even though
  * no other changes have been made
  */
 function testActiveRecordChangeTopLevelIdFeedsDownToRelations()
 {
     $client = Client::findOne(1);
     $this->assertInstanceOf(Client::className(), $client);
     $this->setService('client', $client);
     $customerId = $this->createTestCustomerAndOrder($client->clientCode);
     $this->assertTrue($customerId !== false && $customerId > 0);
     $this->checkBaseCounts('full', $client->clientCode);
     $customer = Customer::findOne($customerId);
     $this->assertInstanceOf(Customer::className(), $customer);
     $customer->id = 95;
     $customerPreChangeWithNewId = $this->updateCustomerIdForComparison($this->cleanDatesForComparison($customer->toArray()), 95);
     $customer->push();
     $customer = Customer::findOne(95);
     $this->assertInstanceOf(Customer::className(), $customer);
     $customerReloaded = $this->cleanDatesForComparison($customer->toArray());
     $this->assertEquals($customerPreChangeWithNewId, $customerReloaded, 'Failed to push new customerId into relations after reload');
 }