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

Allow "from" class in many_many through to accept subclasses #11229

Closed
GuySartorelli opened this issue May 10, 2024 · 1 comment
Closed

Allow "from" class in many_many through to accept subclasses #11229

GuySartorelli opened this issue May 10, 2024 · 1 comment

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented May 10, 2024

Subclasses should be allowed to declare usage of a given many_many through join class. For example, say I have a module that provides a MySpecialModel class. I want to make it easy to have a many_many through relation from this class to pages - but explicitly to pages. My use case doesn't allow random dataobjects to own my special model.

The below code demonstrates how this could be used (replacing MySpecialModel with Image so you can dump this int a project and try it out).

This fails because the linking object's relation class doesn't exactly match the owner. Sharing the linking objects across various entries in the ancestry should be a supported use case.

class HomePage extends Page
{
    private static $many_many = [
        'HeroImages' => [
            'through' => PageImageLink::class,
            'from' => 'Page',
            'to' => 'Image',
        ]
    ];

}
class PageImageLink extends DataObject
{
    private static $has_one = [
        'Page' => SiteTree::class,
        'Image' => Image::class,
    ];
}

PRs

@GuySartorelli
Copy link
Member Author

@emteknetnz You've assigned this to me but the PR is merged - before I close this I just want to double check if that was a mistake, or if there's something I'm missing here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants