I'm trying to implement relationship on two columns, record_id and table_name,
here is what I got so far, Model name BatteryAssets:
public function Attachments()
{
return $this->hasMany('App\Attachments','record_id','id')->where('tabel_name','`battery_assets`');
}
please note that 'battery_asstes' is a string, so it's not dynamic, I'm trying to make it as a string, but get the following error :
QueryException in Connection.php line 761:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tabel_name' in 'where clause' (SQL: select * from `attachments` where `attachments`.`record_id` = 1 and `attachments`.`record_id` is not null and `tabel_name` = `battery_assets`)
as you see I'm I have tried to put battery_assets into `` and also I've tried to put them into double quotes ' "battery_assets" ' and also no quotes
and also please not that BatteryAssets table does not have table_name column, I'm only want to use it as a static value in the where clause, also I've tryied to do
->where('attachments.tabel_name','"battery_assets"');
but It gives the same error
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire