Beispiel #1
0
 public static function dispense($table)
 {
     if (!Validate::table($table)->exists()) {
         return self::$table();
     }
     return true;
 }
Beispiel #2
0
 /**
  * Delete fields from array
  * @param array $fields Indexed array
  */
 public function deleteFields(array $fields)
 {
     $fields = Helpers\Validate::arrToLower($fields);
     Helpers\Validate::table($this->name)->fields($fields);
     $config = $this->config();
     $config->schema = array_diff_key($this->schema(), array_flip($fields));
     $data = $this->getData();
     foreach ($data as $key => $object) {
         foreach ($fields as $name) {
             unset($data[$key]->{$name});
         }
     }
     Helpers\Data::table($this->name)->put($data);
     Helpers\Config::table($this->name)->put($config);
 }
Beispiel #3
0
 /**
  * Add data to configs and create all necessary files
  */
 protected function addRelation()
 {
     if ($this->relationType == 'hasAndBelongsToMany') {
         $junction = $this->getJunction();
         try {
             Validate::table($junction)->exists();
         } catch (LazerException $e) {
             Database::create($junction, array($this->tables['local'] . '_id' => 'integer', $this->tables['foreign'] . '_id' => 'integer'));
             $this->insertRelationData($junction, $this->tables['local'], 'hasMany', array('local' => $this->tables['local'] . '_id', 'foreign' => $this->keys['local']));
             $this->insertRelationData($junction, $this->tables['foreign'], 'hasMany', array('local' => $this->tables['foreign'] . '_id', 'foreign' => $this->keys['foreign']));
         }
     }
     $this->insertRelationData($this->tables['local'], $this->tables['foreign'], $this->relationType, $this->keys);
 }