In BreadRelationshipParser Trait, getRelationships() method always return empty array since it is checking if the details column of Data Rows Table has relationship . But while saving bread with relationship, bread doesn't save relationship field on details column on Data Rows table.
$dataType->browseRows->each(function ($item) use (&$relationships) {
$details = json_decode($item->details);
if (isset($details->relationship) && isset($item->field)) {
....
Steps to reproduce the behavior:
1.Create a Bread with any relationship
Simply looking at the code/database I can confirm that.
The condition should be
if ($details->type == 'relationship')
@emptynick Exactly. :+1:
Simply looking at the code/database I can confirm that.
The condition should be
if ($details->type == 'relationship')
I just re-confirmed on the database that, if the datatype is "relationship" we have data in $item->type as 'relationship', but in $details->type we have value as 'belongsTo'.
DataRows Table's fields having relationship data :

Same DataRows table's detail field data
But is Code we have the above.
@emptynick I think this parser is never used in current version of voyager. Currently, the relationship data are fetched in view by directly calling the models relations method. Just need to know if you guys have plan to use the parser ?
@DrudgeRajen I'm getting a possibly-related issue where when I try to create a new BREAD with a relationship, i get an error:

This is making Voyager useless to me since i cannot add new tables with BREAD and relationships.
@adrienne no, thats not related. Also this Trait is not used in the BreadController (I see VoyagerBaseController) in your screenshot
@emptynick - this is happening when i have created BREAD and am trying to get to the listing/browse page. It will not show me the browse page, this is the error.
I just figured out the fix, though - if you deselect "Browse" from the BREAD options for the parent field, this error goes away. I'll write up a new bug report.
@adrienne it doesn't relate with this issue. Would you please create a new issue for yours one?
I checked the code and find getRelationships() method of BreadRelationshipParser is not working.
$dataType->browseRows->each(function ($item) use (&$relationships) {
$details = json_decode($item->details);
if ($item->type === 'relationship' && isset($item->field)) {
$relation = $details;
if (isset($relation->method)) {
$method = $relation->method;
$this->relation_field[$method] = $item->field;
} else {
$method = camel_case($item->field);
}
$relationships[$method] = function ($query) use ($relation) {
// select only what we need
if (isset($relation->method)) {
return $query;
} else {
$query->select($relation->key, $relation->label);
}
};
}
});
return $relationships;
Because the model will try to call the method that was saved in field column of data_rows table and eloquent builder will throw exception as the method will not be in model.
Any progress here? I have run into the same issue.
I'm a bit confused what the problem is and if it is a problem at all.
The condition is wrong, but the things in the database seems ok?
I'm suffering the same problem after creating a "belongsTo" relation. I tried different table and model names and the error still occurs.
In BreadRelationshipParser.php:
$bread_data = $dataType->browseRows->where('field', $field)->first();
$bread_data is always NULL and I just wondering what "browseRows" is? Function or variable?
In my case the value of $field is "customer_cat" and I assume this line is looking for data in table data_rows, but no data with field value "customer_cat". Is it possible a bug when creating a relation?
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
Any progress here? I have run into the same issue.