for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Nip\Records\Traits\ActiveRecord;
use Nip\Records\AbstractModels\Record;
use Nip\Records\Traits\AbstractTrait\RecordTrait;
use Nip\Records\Traits\HasPrimaryKey\RecordTrait as HasPrimaryKeyTrait;
/**
* Class ActiveRecordTrait
* @package Nip\Records\Traits\ActiveRecord
*/
trait ActiveRecordTrait
{
use RecordTrait;
use HasPrimaryKeyTrait;
protected $dbData = [];
* @param bool|array $data
public function writeDBData($data = false)
foreach ($data as $key => $value) {
$this->dbData[$key] = $value;
}
* @return array
public function getDBData()
return $this->dbData;
* @param $field
* @return bool
public function fieldUpdatedFromDb($field)
if (!isset($this->{$field})) {
return false;
if (!isset($this->dbData[$field])) {
if ($this->{$field} == $this->dbData[$field]) {
return true;
public function insert()
$pk = $this->getManager()->getPrimaryKey();
$lastId = $this->getManager()->insert($this);
if ($pk == 'id') {
$this->{$pk} = $lastId;
return $lastId > 0;
* @return bool|\Nip\Database\Result
public function update()
$return = $this->getManager()->update($this);
return $return;
public function save()
$this->getManager()->save($this);
public function saveRecord()
public function delete()
$this->getManager()->delete($this);
public function isInDB()
$primaryKey = $this->getManager()->getPrimaryKey();
return $this->{$primaryKey} > 0;
* @return bool|false|Record
public function exists()
return $this->getManager()->exists($this);