change ref_class to ref_model

This commit is contained in:
Nabeel Shahzad
2018-04-01 14:32:01 -05:00
parent 0bed38c78b
commit 793b3e7134
31 changed files with 211 additions and 211 deletions

View File

@@ -7,8 +7,8 @@ use App\Interfaces\Model;
/**
* The Award model
* @property mixed id
* @property mixed ref_class
* @property mixed|null ref_class_params
* @property mixed ref_model
* @property mixed|null ref_model_params
* @package Award\Models
*/
class Award extends Model
@@ -19,16 +19,16 @@ class Award extends Model
'name',
'description',
'image_url',
'ref_class',
'ref_class_params',
'ref_model',
'ref_model_params',
];
public static $rules = [
'name' => 'required',
'description' => 'nullable',
'image_url' => 'nullable',
'ref_class' => 'required',
'ref_class_params' => 'nullable'
'ref_model' => 'required',
'ref_model_params' => 'nullable'
];
/**
@@ -39,12 +39,12 @@ class Award extends Model
*/
public function getReference(Award $award = null, User $user = null)
{
if (!$this->ref_class) {
if (!$this->ref_model) {
return null;
}
try {
return new $this->ref_class($award, $user);
return new $this->ref_model($award, $user);
} catch (\Exception $e) {
return null;
}

View File

@@ -8,8 +8,8 @@ use App\Interfaces\Model;
* @property int airline_id
* @property float amount
* @property string name
* @property string ref_class
* @property string ref_class_id
* @property string ref_model
* @property string ref_model_id
* @package App\Models
*/
class Expense extends Model
@@ -23,8 +23,8 @@ class Expense extends Model
'type',
'multiplier',
'charge_to_user',
'ref_class',
'ref_class_id',
'ref_model',
'ref_model_id',
'active',
];
@@ -42,18 +42,18 @@ class Expense extends Model
*/
public function getReference()
{
if (!$this->ref_class || !$this->ref_class_id) {
if (!$this->ref_model || !$this->ref_model_id) {
return null;
}
if ($this->ref_class === __CLASS__) {
if ($this->ref_model === __CLASS__) {
return $this;
}
try {
$klass = new $this->ref_class;
$klass = new $this->ref_model;
return $klass->find($this->ref_class_id);
return $klass->find($this->ref_model_id);
} catch (\Exception $e) {
return null;
}

View File

@@ -130,8 +130,8 @@ class Journal extends Model
{
return $this
->transactions()
->where('ref_class', \get_class($object))
->where('ref_class_id', $object->id);
->where('ref_model', \get_class($object))
->where('ref_model_id', $object->id);
}
/**

View File

@@ -16,8 +16,8 @@ use App\Interfaces\Model;
* @property string post_date
* @property integer credit
* @property integer debit
* @property string ref_class
* @property integer ref_class_id
* @property string ref_model
* @property integer ref_model_id
* @property Journal journal
*/
class JournalTransaction extends Model
@@ -34,8 +34,8 @@ class JournalTransaction extends Model
'currency',
'memo',
'tags',
'ref_class',
'ref_class_id',
'ref_model',
'ref_model_id',
'post_date'
];
@@ -67,8 +67,8 @@ class JournalTransaction extends Model
*/
public function referencesObject($object)
{
$this->ref_class = \get_class($object);
$this->ref_class_id = $object->id;
$this->ref_model = \get_class($object);
$this->ref_model_id = $object->id;
$this->save();
return $this;
@@ -79,10 +79,10 @@ class JournalTransaction extends Model
*/
public function getReferencedObject()
{
if ($classname = $this->ref_class) {
$klass = new $this->ref_class;
if ($classname = $this->ref_model) {
$klass = new $this->ref_model;
return $klass->find($this->ref_class_id);
return $klass->find($this->ref_model_id);
}
return false;

View File

@@ -375,8 +375,8 @@ class Pirep extends Model
public function transactions()
{
return $this->hasMany(JournalTransaction::class, 'ref_class_id')
->where('ref_class', __CLASS__)
return $this->hasMany(JournalTransaction::class, 'ref_model_id')
->where('ref_model', __CLASS__)
->orderBy('credit', 'desc')
->orderBy('debit', 'desc');
}

View File

@@ -19,8 +19,8 @@ trait ExpensableTrait
return $this->morphMany(
Expense::class,
'expenses', # overridden by the next two anyway
'ref_class',
'ref_class_id'
'ref_model',
'ref_model_id'
);
}
}