Hey,
I'm implementing an application which allows the user to individually create a table layout for a specific purpose. All tables contain the same schema to some extend (id, updated, created, deleted, ...) but are extensible to some degree by the users input (add column, define column type, ...). All tables will be named using the following convention "table_$id". I would like to use one model which retrieves the current id from my input (new Model()->setId($id)) and sets the table name accordingly.
How can I tell the model to retrieve the remaining table schema data from the live db while using some default values using the annotations schema? Or would you recommend an entirely different way to do this? :)
Thanks in advance for your feedback, Philipp
Example code:
<?php
class ModelWithChangingID extends Model
{
/**
* @Primary
* @Identity
* @Column(type="integer", nullable=false)
*/
public $id;
/**
* @Column(type="integer", nullable=false)
*/
public $entity_id;
/**
* @Column(type="datetime", nullable=false)
*/
public $created;
/**
* @Column(type="datetime", nullable=true)
*/
public $updated;
/**
* @Column(type="integer", nullable=true)
*/
public $deleted;
protected $_id;
public function getSource()
{
if (empty($this->_id))
{
throw new \Exception('Table id can not be empty');
}
return 'table_' . $this->getId();
}
public function getId()
{
return $this->_id;
}
public function setId($id)
{
$this->_id = $id;
}
}