namespace Library\Models\Properties\Base;
class Property
{
const TABLE_NAME = 'properties';
public $loanId;
public $addressId;
public $propertyTypeId;
public $propertyUseId;
/**
* Initialize method for model
*/
public function initialize()
{
parent::initialize();
$this->hasOne(
'addressId',
'Library\Models\Addresses\Base\Address',
'id', ['alias' => 'Address']);
$this->hasOne(
'propertyTypeId',
'Library\Models\Types\PropertyType',
'id', ['alias' => 'PropertyType']);
$this->hasOne(
'propertyUseId',
'Library\Models\Types\PropertyUseType',
'id', ['alias' => 'PropertyUseType']);
}
/**
* Independent Column Mapping.
* Keys are the real names in the table and the values their names in the application
*
* @return array
*/
public function columnMap()
{
return
[
'loan_id' => 'loandId',
'address_id' => 'addressId',
'property_type_id' => 'propertyTypeId',
'property_use_id' => 'propertyUseId'
];
}
}
namespace Library\Models\Addresses\Base;
class Address
{
const TABLE_NAME = 'addresses';
const BLANK_FIELD = "''";
public $loanId;
public $address1;
public $address2 = self::BLANK_FIELD;
public $city;
public $state;
public $zip;
public $country;
/**
* Initialize method for model
*/
public function initialize()
{
parent::initialize();
$this->belongsTo(
'id',
'Library\Models\Properties\Base\Property',
'addressId', ['alias' => 'Property']);
}
/**
* Independent Column Mapping.
* Keys are the real names in the table and the values their names in the application
*
* @return array
*/
public function columnMap()
{
return
[
'loan_id' => 'loandId',
'address1' => 'address1',
'address2' => 'address2',
'city' => 'city',
'state' => 'state',
'zip' => 'zip',
'country' => 'country'
];
}
}
{
$property = new \Library\Models\Properties\Base\Property();
$property
->setLoanId('96')
->setPropertyUseId('1')
->setPropertyTypeId('1');
$address = new Address();
$address
->setLoanId('96')
->setAddress1('3456 Some Street')
->setCity('Yuck')
->setState('MO')
->setZip('12345')
->setCountry('USA');
$property->address = $address;
if ($property->save() == false) {
foreach ($property->getMessages() as $message) {
echo $message;
}
}
}