First things first, thank you for creating such a great tool.
As of now it is the best i've used (and i've had my fair share of attempts with admin tools).
Now, i have voyager working and property configured. Creating tables, models, BREAD and menus.
So far all good.
The issue i am having has to do with setting up the relationships on BREAD according to the documentation here https://the-control-group.github.io/voyager/docs/v0.10/#core-concepts-bread-relationships .
According to this logic, if a have a User, and this user belongs to a Team model (whilst having a team_id in the user table) i would need to create a teamId() relationship.
And that does not sound quite right. I would also add that it's a bit counterintuitive as far as doing things the Laravel-way goes.
If i want to get the user's team, the relationship should be team() and not teamId().
After all i am getting back a Team instance from the relationship and not the id of that instance, which i can access with user->team->id().
I chased this all the way down to BreadRelationshipParser but i really don't want to mess with vendor code for obvious reasons.
Now, my question is: Is there a way to override the relationship name that Voyager expects to find on the model?
In this case from teamId() to simple team()?
best regards and thank you in advance
I see, this should indeed be made into a configuration.
Maybe it could use a method value from the JSON parameters like this:
{
"relationship": {
"method": "team"
}
}
@marktopper Absolutely.
Also imagine not only relationships in the conventional sense but also computed and appended fields.
As of now, the package forces a convention that for large or existing projects becomes unsustainable.
In the current case, i'm implementing Voyager on a codebase with about 50 models that have 15-20 relations each.
There is no way i'm duplicating all those methods... :/
I started slowly working on a local patch that might get me rolling for a bit and then if it becomes something solid i will certainly do a pull request but the whole mixup of snake_case and camel_case on BreadRelationshipParser is a bit of a show stopper.
Would be awesome with a pull request for this @sidis405 馃帀
:) Yea i'd love to help. And now i'm also noticing that this logic is baked in a lot of places. Including blade files. Perhaps because of the way the datatype is saved.
Well, i need to get it working for my project one way or another as i really enjoy this package.
I'll make sure to share.
@sidis405 this would be a huge improvement for voyager. looking forward to your pull request.
@peacemoon Indeed it would be nice. All and all i slowly got it working with e correct relationships being shown but there are still some doubtful areas, say in BreadRelationshipParser where i don't see any support code for ManyToMany relationships making it present on Add/Edit but not on browse and read.
I added it but i would need to openly discuss with someone that is familiar with the file to see if i'm implementing in the spirit of the voyager logic.
Okay i think i got something.
If i make a quick pull request does someone wanna take a look at it for additional stuff we can add?
So far basically i have the following implemented :
{
"relationship": {
"method": "team"
}
}
{
"relationship": {
"key": "sports.id",
"label": "name",
"method": "sports"
}
}
I don't know how this worked before but it never worked for me correctly as the 'id' field was not unique
best
sid
If you make a pull request I will test it out and do a review. 馃憤
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
:) Yea i'd love to help. And now i'm also noticing that this logic is baked in a lot of places. Including blade files. Perhaps because of the way the datatype is saved.
Well, i need to get it working for my project one way or another as i really enjoy this package.
I'll make sure to share.