Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern: relations array #78

Open
boazpoolman opened this issue Apr 21, 2022 · 5 comments
Open

Pattern: relations array #78

boazpoolman opened this issue Apr 21, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@boazpoolman
Copy link
Member

boazpoolman commented Apr 21, 2022

Feature request

Summary

As of #75 you can add relation fields to the URL pattern like so:

/test/[relation.field]/[id]

Though this only works for single relations. If the relation would be of target *ToMany we wouldn't know which entity to query exactly.

Suggested solution(s)

We should allow the pattern to be written like this to select a specific item of an array of relations.

/test/[relation[1].field]/[id]

Here we would select the second entity on the relations array.

@kibblerz
Copy link
Contributor

So I did come up with a more optimal way to solve this. This method should also open the door for greater customization and resolution of other niche cases:

We could add a way where a custom "resolver" could be injected from the plugins config. I haven't implemented it yet, but it is a promising solution IMO. That way, user's can override the default resolution. We'd just pass in the relevant record and the user would be responsible for changing that into a path.

We'd likely have to disable editing the content type in the admin if a custom resolver is being used, but other than that I believe it's a promising route.

@boazpoolman
Copy link
Member Author

That does sound promising !

Just so we're on the same page. You mean you would write some plugin config to register for example my-key. Which can be any value you assign to it.

So that we can then create a pattern like: /test/[id]/[my-key].

Did I get that right?

@candidosales
Copy link

I'm trying to generate a new URL bundle as/post/[cities[0].slug]/[slug], but it isn't working.

I have a relationship ManyToMany between posts and cities.

Could you help me?

@boazpoolman
Copy link
Member Author

Hi @candidosales.

Thank you for your interest in this feature.

Sadly *ToMany relations are not yet supported in URL patterns.
A couple of possible solutions have been suggested here by myself and kibblerz, though none have been implemented as of yet.
I'm afraid you'll have to be patient until I find time to work on this feature, or take a stab at it yourself.

@candidosales
Copy link

Hi @boazpoolman ,

I'm working on it: #139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants