Giter VIP home page Giter VIP logo

Comments (7)

duellsy avatar duellsy commented on August 15, 2024

Hmmm interesting, if there's any issues in determining which fields have been updated and which are unchanged, it points to a possible bug in Eloquents getDirty() function: https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Eloquent/Model.php#L2162

In particular, the following line is equating to true:

if ( ! array_key_exists($key, $this->original) or $value != $this->original[$key])

Since the key would exist in the original array, it seems as though $value != $this->original[$key] is true...

As a test, perhaps do a var_dump of the object as it currently exists, and then also directly before saving it, and compare the value on initial load and then before saving

from revisionable.

arenowebdev avatar arenowebdev commented on August 15, 2024

Yep...that is the problem. http://paste.laravel.com/wEV

Looks like it's being cast to an integer where when it's in the database it is a string. I just confirmed that the disabled field is a boolean in the migration $table->boolean('disabled')->default(0);...

Not sure if you typo'd it or not, but in my version of Laravel that line is:
if ( ! array_key_exists($key, $this->original) or $value !== $this->original[$key])
(notice the double equal...). Just to be certain, I changed mine to a single equal and it still has the same problem. Hmmm...time to file a bug on the Laravel repo? Do you experience the same issue on boolean fields?

from revisionable.

duellsy avatar duellsy commented on August 15, 2024

I copied that line from the Laravel project in it's latest form on github.

Might be worth opening an issue in Laravel to confirm that it is correct behaviour... if they feel that booleans should continue to be cast to an int when pulled from the database, then we'll have to adhere to that and make a fix to cater for it.

from revisionable.

duellsy avatar duellsy commented on August 15, 2024

Oh actually... my apologies, the latest Laravel has !==, I was looking at an older version. This more explicit comparison wouldn't be helping, since in theory
true != 0 would return a fail

Seems it was updated in Laravel about a month back laravel/framework@e247073

from revisionable.

arenowebdev avatar arenowebdev commented on August 15, 2024

Found the fix here after asking in IRC. :P

laravel/framework#1429 (comment)

from revisionable.

duellsy avatar duellsy commented on August 15, 2024

Awesome, nice find. If enough other people have this issue, then we'll look at putting this in revisionable core

from revisionable.

arenowebdev avatar arenowebdev commented on August 15, 2024

I can't seem to get this to work, unfortunately. Even when I have the getAttribute in my base model, it never gets called on my boolean fields if they are changing. Any ideas? I think I'm in need of tutoring... 😄

from revisionable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.