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

Question: Could GridFieldOrderableRows::reorderItems() please use ORM for non-Versioned models? #335

Closed
chrispenny opened this issue Feb 22, 2022 · 3 comments · Fixed by #336

Comments

@chrispenny
Copy link
Contributor

Current implementation

When a model does not implement the Versioned extension, reorderItems() uses SQL queries to update the sort values of models.

When a model does implement the Versioned extension, reorderItems() sets the sort value on the record and performs a write() through the ORM.

Problem statement

When developers implement onBeforeWrite() and onAfterWrite() methods, there is some confusion on whether or not these methods will be called when the records are reordered. If they are Versioned, then these methods will be triggered; if they are not Versioned, then they will not.

Question

Could we please standarise the reorderItems() method to always use the ORM to save records?

Considerations

Would this sort of change need to be a new major version, or would it be considered a "bugfix"?

@emteknetnz
Copy link
Collaborator

Code being referred to is here

Unversioned SQL

'UPDATE "%s" SET "%s" = %d%s WHERE %s',

Versioned ORM sort

$record->$sortField = $newSortValue;

@emteknetnz
Copy link
Collaborator

I'd call it an enhancement (ENH prefix).

I don't see why this would need a new major. New minor seems fine since there would be a behavioral change as $record->write() would now be getting called, instead of the current behavior on not called with the stealth update via raw SQL.

Happy to peer review if you can provide a PR. There's some existing tests in GridFieldOrderableRowsTest.php, though you may need to add to these depending on existing coverage. Looks like there a few use cases listed within inline comments in reorderItems() that will need to be considered

@chrispenny
Copy link
Contributor Author

Perfect! Thanks, @emteknetnz. I will work on that PR soon 😄

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

Successfully merging a pull request may close this issue.

2 participants