I am working on a small task managment tool for logged in user. For this, I use the ORM and the auth package.
My goalis to limit allquery's to the database tables to the specific user_id of the user logged in. I know, I could add to every single query a "where" condition like "where user_id = XYZ", but is there a better way to do that?
My first suggest was to add a "protected static $_conditions" variable to the Models. But I can't use "Auth::get_user_id()" in a static class variable:
Ok, I solved it by setting a constant in the controller before method. At least, the documentation is wrong, since you can't use methods/functions in static variables.
You can only use scalars in property definitions, no function calls. In any type of property. If needed, you can work around that by setting the value at runtime in the _init() method of the Model class.
I'll fix the example, time() is a function call too, so obviously that fails for the same reason.
Other then that, conditions work fine, both on the model and on individual relations.