Пример #1
0
 /**
  * Overrides the initialize to automatically provide the column name
  *
  * @param   string  $model
  * @param   string  $column
  * @return  void
  */
 public function initialize($model, $column)
 {
     // Default to the name of the column
     if (empty($this->foreign)) {
         $foreign_model = inflector::singular($column);
         $this->foreign = $foreign_model . '.' . $foreign_model . ':primary_key';
     } elseif (FALSE === strpos($this->foreign, '.')) {
         $this->foreign = $this->foreign . '.' . $this->foreign . ':primary_key';
     }
     // Split them apart
     $foreign = explode('.', $this->foreign);
     // Create an array from them
     $this->foreign = array('model' => $foreign[0], 'column' => $foreign[1]);
     // We can work with nothing passed or just a model
     if (empty($this->through) or is_string($this->through)) {
         if (empty($this->through)) {
             // Find the join table based on the two model names pluralized,
             // sorted alphabetically and with an underscore separating them
             $through = array(inflector::plural($this->foreign['model']), inflector::plural($model));
             // Sort
             sort($through);
             // Bring them back together
             $this->through = implode('_', $through);
         }
         $this->through = array('model' => $this->through, 'columns' => array(inflector::singular($model) . ':foreign_key', inflector::singular($this->foreign['model']) . ':foreign_key'));
     }
     parent::initialize($model, $column);
 }
Пример #2
0
 /**
  * Overrides the initialize to automatically provide the column name
  *
  * @param   string  $model
  * @param   string  $column
  * @return  void
  */
 public function initialize($model, $column)
 {
     // Default to the name of the column
     if (empty($this->foreign)) {
         $this->foreign = inflector::singular($column) . '.' . $model . ':foreign_key';
     } elseif (FALSE === strpos($this->foreign, '.')) {
         $this->foreign = $this->foreign . '.' . $model . ':foreign_key';
     }
     // Split them apart
     $foreign = explode('.', $this->foreign);
     // Create an array from them
     $this->foreign = array('model' => $foreign[0], 'column' => $foreign[1]);
     parent::initialize($model, $column);
 }
Пример #3
0
 /**
  * Automatically sets foreign to sensible defaults
  *
  * @param   string  $model
  * @param   string  $column
  * @return  void
  */
 public function initialize($model, $column)
 {
     // Default to the name of the column
     if (empty($this->foreign)) {
         $this->foreign = $column . '.:primary_key';
     } elseif (FALSE === strpos($this->foreign, '.')) {
         $this->foreign = $this->foreign . '.:primary_key';
     }
     // Split them apart
     $foreign = explode('.', $this->foreign);
     // Create an array from them
     $this->foreign = array('model' => $foreign[0], 'column' => $foreign[1]);
     // Default to the foreign model's primary key
     if (empty($this->column)) {
         $this->column = $this->foreign['model'] . '_id';
     }
     // Column is set and won't be overridden
     parent::initialize($model, $column);
 }