php-activerecord icon indicating copy to clipboard operation
php-activerecord copied to clipboard

Modify value before being cast

Open danielbrodin opened this issue 10 years ago • 1 comments

Hi

I have a column in the table where I want to save an int, the problem however is when a new record is created I want to send the value as a string to the class, then have a method that converts it to the correct int value before save/create.

Is this currently possible? As far as I have found cast() is always being run before any callbacks.

I think that if available, set_$name() should be run either before cast() or even instead of it.

danielbrodin avatar Feb 16 '15 10:02 danielbrodin

This has been reported before (#238), and I agree that custom setters should be called before casting. But up until now there is no patch, so if you have the time to implement this and send us a PR I would be more than happy to merge.

koenpunt avatar Feb 16 '15 12:02 koenpunt