Change protected attrs to static protected.

This commit is contained in:
kj 2020-05-11 03:11:11 -04:00
parent 2ba6079f17
commit c9f6887d5b
1 changed files with 10 additions and 11 deletions

View File

@ -18,10 +18,9 @@ class ModelMySQL {
public $id;
protected $primaryKey = 'id';
protected $ignoreSave = ['id'];
protected $forceSave = [];
static protected $primaryKey = 'id';
static protected $ignoreSave = ['id'];
static protected $forceSave = [];
static protected $table;
static protected $tableSufix = 's';
static protected $db;
@ -185,11 +184,11 @@ class ModelMySQL {
$result[$att] = $this->$att;
}
foreach ($this->ignoreSave as $del) {
foreach (static::$ignoreSave as $del) {
unset($result[$del]);
}
foreach ($this->forceSave as $value) {
foreach (static::$forceSave as $value) {
$result[$value] = $this->$value;
}
@ -229,7 +228,7 @@ class ModelMySQL {
}
$table = static::table();
$pk = $this->primaryKey;
$pk = static::$primaryKey;
$pkv = $this->$pk;
$sql = "UPDATE $table SET ".join(', ', $set)." WHERE $pk='$pkv'";
static::query($sql);
@ -252,7 +251,7 @@ class ModelMySQL {
$sql = "INSERT INTO $table (".join(', ', $into).") VALUES (".join(', ', $values).")";
static::query($sql);
$pk = $this->primaryKey;
$pk = static::$primaryKey;
$this->$pk = $db->insert_id;
}
@ -261,7 +260,7 @@ class ModelMySQL {
* llama a update para actualizar o add para insertar una nueva fila.
*/
public function save() {
$pk = $this->primaryKey;
$pk = static::$primaryKey;
if (isset($this->$pk))
$this->update();
else
@ -280,7 +279,7 @@ class ModelMySQL {
}
$table = static::table();
$pk = $this->primaryKey;
$pk = static::$primaryKey;
$pkv = $this->$pk;
$sql = "DELETE FROM $table WHERE $pk='$pkv'";
static::query($sql);
@ -622,7 +621,7 @@ class ModelMySQL {
* @return ModelMySQL
*/
public static function getById($id) {
return static::where('id', $id)->getFirst();
return static::where(static::$primaryKey, $id)->getFirst();
}
/*