-
Notifications
You must be signed in to change notification settings - Fork 280
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
Changing only some bean properties can fail #547
Comments
@gabordemooij Any input on this? At the moment I have to run the |
Hi there, thank you for reporting this. |
I am setting up a new RedBeanPHP devbox as we speak... |
Hm I tried to reproduce this issue, but I couldnt...
this works just fine... did you add the boolean type column by yourself? |
@gabordemooij Thanks so much for looking into this! Aah, I see, because your column is set as an integer for the boolean by default. Try this and then retest your exact code: ALTER TABLE bean ALTER COLUMN yes TYPE boolean USING yes::boolean; |
Okay, yes this probably why RedBeanPHP fails, I can now reproduce the issue. Easiest way to solve this would be to create a cast for text to boolean, I think I'll research that option first. I also liked your idea about only storing partial beans (only changed properties) but then I remembered people seem to depend on this behavior (i.e. race-conditions, duplications etc). |
For some reason, I dont seem to able to create a cast in PostgreSQL to convert a value of 'type unknown' which seems to be the case for literals to 'boolean'. I am now working on a solution using the partial-save you proposed. I think I'll add an option to activate this behavior so it remains backward compatible: R::usePartialBeans( true ); what do you think? |
Hi @gabordemooij Absolutely @ remains backward compatible. I think As far as I saw when browsing the code, each property gets a meta field assigned to it that remembers if it's been changed or not, right? |
Not really, only if 'a property' has been changed. To this end I added the meta property 'changelist'. The changelist will keep track of changed properties. |
Can you try this fix? I updated the master. |
me trying without adding me realising that I forgot Looking forward to the next release! 👍 |
Thanks for confirming the fix. I'll release a new version asap. |
When I load a bean (via
$bean = R::findOne(...);
), only change a few values and then callR::store($bean);
, it can happen that I get an error like:Error in SQL query: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type boolean: ""
This happens, when there is a boolean field set to
false
and I don't update that field. WhenR::store()
is called, the value isn't translated to'0'
but instead staysfalse
. PostgreSQL doesn't like this.When setting a boolean value, it gets converted correctly, but any unchanged values stay of type
boolean
.This can be fixed by (re)setting all properties, like so, in
RedBeanPHP/Repository/Frozen.php
just before getting the properties to be saved.Surely not the cleanest way, but it works.
Alternatively, I could run that foreach loop just before calling
R::store($bean);
, but I think this should be part of the library itself.Hope this is explained well enough, else just ask 👍
The text was updated successfully, but these errors were encountered: