/** * Create a new table object. * * @method __construct * * @param string $name The table name * @param string|null $alias An alias for use in queries * @param Instance|null $instance The instance the table belongs to */ public function __construct($name, $alias = null, Instance $instance = null) { $this->name = $name; if ($alias === null) { $alias = $name; } $this->alias = $alias; $instance = $instance ?: Database::instance('default'); $this->instance = $instance; $this->primaryKey = $this->instance->primaryKeyForTable($this); $this->fields = $this->instance->fieldsForTable($this); $this->relationships = $this->instance->relationshipsForTable($this); $instance::$tableCache[$name . '.' . $alias] = $this; }
/** * Create a new query. * * @param Table|string $table The table to query * @param string|null $alias An alias to use * @param Instance|null $instance The instance to use */ public function __construct($table, $alias = null, Instance $instance = null) { // If a table name is passed, rather than an instance of Table, // then create the table object here if (!$table instanceof Table) { $table = Table::find($table, $alias); } $this->table = $table; $this->instance = $instance ?: Database::instance('default'); }