-
Notifications
You must be signed in to change notification settings - Fork 821
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
[ORM] Database field names are not guarded against ORM method clashes #6329
Comments
Alright, so what we need is a better check for reserved keys for properties, similar to how we do for form actions. What you would expect is that framework would crash with a "Invalid property name" error right? E.g. a property |
I suggest to put the fix in DataObject::db() method (or DataObjectSchema::fieldSpec method in 4.x). To improve performance, maybe the check should only be in dev mode. |
The cause of this is that I think reserving all method names from being DB names is a bit much and surely we'd have to also reserve all the controller methods and all methods on the class hierarchy of both model and controllers too? Oh and decorators, then any What happens if I add a method later with the same name or I install a new module which causes a clash? Who's wrong, the method or the DB field? Brutally honest mode engaged:
What scenario is it even needed to store a boolean on an object called "delete"? |
I would say:
Would accept getName() as a method, but it should fail if Unlike relation names, however, we can't easily guard against these. However, instead we can fail on names that clash with a PARENT class. E.g. These errors would be checked on dev/build. Does this sound reasonable? |
gah - I'd just tell people to be sensible with their naming ;) but yes, that sounds reasonable |
Does this imply that destructive methods like |
Consider this:
Each time the administration is reloaded, the data for that model is removed from the database.
This removed more than 300 documents from my database.
This is because SilverStripe calls the Delete() method in $summary_fields
Which in this case is a very very sensitive method.
In some cases, this little trick of SilverStripe can go very fast and save lives.
But destroys data now. And it took me 48 hours and think that I was attacking, siphoning ...
For example, you can update the Delete method of the DataObject model to:
So to call the Delete method, $now must take true, so that the data is deleted.
PRs
The text was updated successfully, but these errors were encountered: