First attempt at scopeExpanded(), included some new fields in QUERYFIELDS.

This commit is contained in:
James Cole 2016-03-02 12:09:34 +01:00
parent b00c7b0ce3
commit b317d1a171

View File

@ -50,22 +50,23 @@ class TransactionJournal extends Model
use SoftDeletes, ValidatingTrait;
/**
* Fields which queries must load..
* Fields which queries must load.
* ['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']
*/
const QUERYFIELDS = ['transaction_journals.*'];
const QUERYFIELDS
= [
'transaction_journals.*',
'transaction_types.type as transaction_type_type', // the other field is called "transaction_type_id" so this is pretty consistent.
];
/** @var array */
protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at', 'interest_date', 'book_date'];
/** @var array */
protected $fillable
= ['user_id', 'transaction_type_id', 'bill_id',
'transaction_currency_id', 'description', 'completed',
'date', 'rent_date', 'book_date', 'encrypted', 'tag_count'];
/** @var array */
protected $hidden = ['encrypted'];
/** @var array */
protected $rules
= [
@ -270,6 +271,18 @@ class TransactionJournal extends Model
return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00'));
}
/**
* @param EloquentBuilder $query
*/
public function scopeExpanded(EloquentBuilder $query)
{
// left join transaction type:
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
// try to get amount
}
/**
* @codeCoverageIgnore
*