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

Reverse ownership #5

Closed
maxime-rainville opened this issue Nov 23, 2020 · 9 comments
Closed

Reverse ownership #5

maxime-rainville opened this issue Nov 23, 2020 · 9 comments
Assignees

Comments

@maxime-rainville
Copy link

maxime-rainville commented Nov 23, 2020

Story

As a developer I want Link objects to have a sensible ownership model so that Link objects behave in a sensible way when versioned operation are performed.

Acceptance criteria

  • We have validated what the ownership relations between Link and their owner object should be.
  • Usage doc provides clear guidance on how to configure ownership when creating Link relations.
  • Ownership model can accommodate situation where link is in Has_many or a Has_One relation.
  • The scenario where two "HAS_Many" link relations are managed on the same DataObject is considered.

Note

The links belongs to a single owner relationship.

POCs

Option one:

Option two:

NOTE: This option could be mostly implemented in framework if we have some new way to define it (e.g. has_one_special) - that's necessary so we know when we should have and use the new dbfield which existing has_one relations won't have.

INSTALLER CI RUN

https://github.com/creative-commoners/silverstripe-installer/actions/runs/7160809301
Note the SilverStripe\CMS\Tests\Model\SiteTreeTest::testRelativeLink failure is pre-existing. See silverstripe/.github#169

PRs

@GuySartorelli
Copy link
Member

Added an alternative solution.

@michalkleiner
Copy link
Contributor

michalkleiner commented Oct 12, 2023

No input as to the issue itself, just o note on the story language — 'sensible' can be quite ambiguous and it's not clear (to me) how to quantify that and what it should express/mean.

@maxime-rainville
Copy link
Author

I had a glance at Guy's solution. I didn't think it was obviously wrong or horrible ... although it seems like a lot of effort to accommodate a rather simple use case.

In the spirit of iteration, what would happen if we just declared that only one link list can be tied to one record? We could wait to see if anyone actually has a use case for having two or more link lists. Could support for multiple Link List on one DataObject retroactively added later on?

@GuySartorelli
Copy link
Member

GuySartorelli commented Oct 16, 2023

We could wait to see if anyone actually has a use case for having two or more link lists.

No need to wait, I had that exact use case multiple times when I was working at signify (different link module, but same use case)

Could support for multiple Link List on one DataObject retroactively added later on?

Arguably yes but adding a relation field like this after the fact would be hard to retrofit, since the data won't be there to filter against.

The better option if you don't want to implement this right off is to just have a simpler permission model, remove the has_one, and accept that we never have access to the 'owner' from the link side of the relationship.

@emteknetnz
Copy link
Member

The better option if you don't want to implement this right off is to just have a simpler permission model, remove the has_one, and accept that we never have access to the 'owner' from the link side of the relationship.

Isn't the difficulty with the can*() checks only an issue for the has_one's on a Page/DataObject?

Seems like what Max is talking about is a separate issue which is support for multiple has_many's on a Page/DataObject.

I don't think there's any issue finding the owner to do can*() checks with the has_many relationships

I'd agree with Guy that we should solve the multiple has_manys now. I don't think Guy's solution was particularly much effort, it's really just an extra column added next to a couple of existing columns.

@GuySartorelli
Copy link
Member

GuySartorelli commented Oct 17, 2023

Isn't the difficulty with the can*() checks only an issue for the has_one's on a Page/DataObject?

It's also a problem for multiple has_many relationships if you don't use a workaround to have all has_many relationships use the same has_one. I'd be strongly against saying we can't support multiple has_many, so we either have to point them all at the same has_one or not have the can* rely on the owner.

@emteknetnz
Copy link
Member

emteknetnz commented Oct 17, 2023

I'm a bit confused - on Max's has_many implementation there was already Link.has_one = [ Owner => DataObject::class ] - which will add the columns OwnerClass + OwnerID to the Link database table - that's enough for you to get the owner easily? Your PR adds OwnerRelation so that we can assign Links to the correct Relation, though I'm not sure why that's necessary to get the Owner specifically?

@GuySartorelli GuySartorelli removed their assignment Oct 18, 2023
@GuySartorelli
Copy link
Member

We have decided to proceed with option 2, pending the creation of a version of the linkfield that can handle has_many relationships. This card is blocked until that has been implemented.

@emteknetnz
Copy link
Member

Linked PRs have been merged

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

No branches or pull requests

4 participants