I have the following schema and model with this seed data .
My goal is to achieve a triangular relationship, this may not be the right term, but finally what I call it.
In three directions:
- Checks have tokens.
- Attached icons have values โโthat are known with the Cheque-> Token binding.
The problem is with the relation from Token to Value , where when I load Values they do not take into account the associated Cheque , therefore, returning all values โโbelonging to Token .
I donโt know if the Value schema is correct for this three-way relationship, so I also doubt that the correct Value relationships belonging to Cheque and Token are correct.
This is how I request models now (excerpt from the installation):
Route::get('test', function() { $cheque = Cheq_Node::with(array('tokens' => function($query) { $query->where_sortable(1); }, 'tokens.values'))->first(); dd( $cheques ); });
I tried changing the link of Token values โโto:
public function values() { return $this->has_many('Cheq_Value', 'token_id')->where_node_id($this->pivot->id); }
But this produced me:
Trying to get property of non-object
Adding Log::dump( dump($this) ) before returning does not show the loaded model, but only the empty Eloquent model:
object(Cheq_Token)[63] public 'attributes' => array (size=0) empty public 'original' => array (size=0) empty public 'relationships' => array (size=0) empty public 'exists' => boolean false public 'includes' => array (size=1) 'values' => null
Not surprisingly, an error occurs here.
How do I make this triangular relationship?