kirkbushell / eloquence

A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.
MIT License
537 stars 58 forks source link

hasMany Relationship return no items #69

Closed warlord0 closed 4 years ago

warlord0 commented 6 years ago

When I enable CamelCasing on my Model it breaks the hasMany relationship.

<?php

namespace App\BuildCtrl;

use Illuminate\Database\Eloquent\Model;
use \Eloquence\Behaviours\CamelCasing;

class GlobalDetails extends Model
{
    use CamelCasing;

    protected $connection = 'competentpersons';
    protected $table = 'vwGlobalDetails';
    protected $primarykey = 'RecordSetKey';

    public $timestamps = false;

    public function workDescription() {
      return $this->hasMany(WorkDescription::class, 'RecordSetKey', 'RecordSetKey');
    }
}

Using:

    return GlobalDetails::where('recordSetKey', '=', $recordSetKey)
        ->with('workDescription')
        ->get();

returns:

"workDescription":[]

If I disable CamelCasing:

"work_description":[{"RecordSetKey":"287","ID":"361","DescriptionOfWorkItem":"Dwelling house"},{"RecordSetKey":"287","ID":"362","DescriptionOfWorkItem":"New consumer unit"},{"RecordSetKey":"287","ID":"363","DescriptionOfWorkItem":"Kitchen"},{"RecordSetKey":"287","ID":"364","DescriptionOfWorkItem":"Cooker"},{"RecordSetKey":"287","ID":"365","DescriptionOfWorkItem":"New installation, rewire or partial rewire"},{"RecordSetKey":"287","ID":"366","DescriptionOfWorkItem":"One or more new circuits"}]

Trouble is I'm using this with vue.js so CamelCasing is really helpful.

kirkbushell commented 4 years ago

Closing as this was raised quite some time ago and I've seen no other similar issues raised.