本文整理汇总了PHP中Sprig::pk方法的典型用法代码示例。如果您正苦于以下问题:PHP Sprig::pk方法的具体用法?PHP Sprig::pk怎么用?PHP Sprig::pk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprig
的用法示例。
在下文中一共展示了Sprig::pk方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _tables
protected function _tables()
{
// Prepare an array to hold tables
$tables = array();
// Create a new database table with name and database
$table = new Database_Table($this->_model->table(), $this->_db);
// Get the model's primary keys as an array
$model_pks = is_array($this->_model->pk()) ? $this->_model->pk() : array($this->_model->pk());
// Loop through each field within the model
foreach ($this->_model->fields() as $field) {
// Check if the field implaments the migratable field interface
if ($field instanceof Sprig_Field_Migratable) {
// Loop through each column in the field
foreach ($field->columns() as $column) {
// Add the column to the table
$table->add_column($column);
}
} elseif ($field->in_db) {
// If the field is unique
if ($field->unique) {
// Add a unique constraint to the table
$table->add_constraint(new Database_Constraint_Unique($field->column));
}
// Loop through every column in the model
foreach ($this->_columns($field, $table) as $column) {
// Add the column to the table
$table->add_column($column);
}
} elseif ($field instanceof Sprig_Field_ManyToMany) {
// ManyToMany fields also contain a pivot table
$pivot = new Database_Table($field->through, $this->_db);
// Get the columns associated with the first half
$columns = $this->_columns(new Sprig_Field_BelongsTo(array('model' => $field->model)), $pivot);
// Foreach column in the first half
foreach ($columns as $column) {
// Add it to the pivot table
$pivot->add_column($column);
}
// Get the columns associated with the second half
$columns = $this->_columns(new Sprig_Field_BelongsTo(array('model' => inflector::singular($this->_model->table()))), $pivot);
// Foreach column in the second half
foreach ($columns as $column) {
// Add it to the pivot table
$pivot->add_column($column);
}
// Add a primary key constraint on all fields within the pivot table
$pivot->add_constraint(new Database_Constraint_Primary(array_keys($pivot->columns()), $pivot->name));
// Add the pivot table to the list of tables
$tables[] = $pivot;
}
}
// Add the primary key constraints to the table
$table->add_constraint(new Database_Constraint_Primary($model_pks, $table->name));
// Add the table to the list
$tables[] = $table;
// And return all tables.
return $tables;
}