当前位置: 首页>>代码示例>>PHP>>正文


PHP Jelly::fields方法代码示例

本文整理汇总了PHP中Jelly::fields方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::fields方法的具体用法?PHP Jelly::fields怎么用?PHP Jelly::fields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jelly的用法示例。


在下文中一共展示了Jelly::fields方法的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->primary_key()) ? $this->_model->primary_key() : array($this->_model->primary_key());
     // 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 Jelly_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 Jelly_Field_ManyToMany) {
             // ManyToMany fields also contain a pivot table
             $pivot = new Database_Table($field->through['model'], $this->_db);
             // Get fields
             $columns = $field->through['columns'];
             foreach ($columns as $field) {
                 // Chekt if the field names are defaults
                 if (strstr($field, ':')) {
                     list($model, $field) = explode(':', $field);
                     // Append the : back onto $field, it's key for recognizing the alias below
                     $field = ':' . $field;
                     // We should be able to find a valid meta object here
                     if (FALSE == ($meta = Jelly::meta($model))) {
                         throw new Kohana_Exception('Meta data for :model was not found while trying to resolve :field', array(':model' => $model, ':field' => $field));
                     }
                     $field = $meta->foreign_key();
                 }
                 $column = Database_Column::factory('int');
                 $column->auto_increment = FALSE;
                 $column->name = $field;
                 $cols[] = $column;
             }
             // Add to pivot
             foreach ($cols 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));
             /**
             * @todo It would be more than appropriate to add a contstraint in a following 
             * form into a database:
             							ALTER TABLE `roles_users`
             						  ADD CONSTRAINT `roles_users_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
             * 
             */
             // 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;
 }
开发者ID:vanameister,项目名称:migration,代码行数:75,代码来源:jelly.php


注:本文中的Jelly::fields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。