j4mie / idiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
http://j4mie.github.com/idiormandparis/
2.01k stars 369 forks source link

Issue with is_dirty #267

Closed tentwofour closed 7 years ago

tentwofour commented 9 years ago

Using Idiorm with Paris; I have a model from which I need to determine if a subset of fields has changed. When setting any of those values to '', or null, the _dirty_fields property is set as such:

_dirty_fields: [
changed_field => 'a new value'
changed_field_set_to_null => 
]

So it knows that 'changed_field_set_to_null' is dirty, and persists it properly. However, asking my model if the property is dirty returns false:

public function save()
{
    if ($this->is_dirty('changed_field_set_to_null')) // false
    {
        // Do stuff
    }
}

Looking in idiorm.php, at the is_dirty method, on line 1966:

public function is_dirty($key) {
    return isset($this->_dirty_fields[$key]);
}

Changing that to correctly triggers that the field is dirty (but not sure if that affects other use-cases, it shouldn't, I don't think...)

public function is_dirty($key) {
    return array_key_exists($key, $this->_dirty_fields);
}

The field in question is a one-to-one relation with another table, the FK is defined on the main table, and setup via 'belongs_to' in my Paris model. Everything works and persists properly, I just can't tell if that one field is actually dirty...

I feel I may be missing something obvious here?

Addvilz commented 9 years ago

This seems like a bug, actually.

tentwofour commented 9 years ago

PR's accepted for bugs?

treffynnon commented 9 years ago

Yes they are.

tag commented 9 years ago

PRs get more consideration when they include unit tests and documentation.

On Apr 7, 2015, at 11:51 AM, Blair D. Patterson notifications@github.com wrote:

PR's accepted for bugs?

— Reply to this email directly or view it on GitHub https://github.com/j4mie/idiorm/issues/267#issuecomment-90617540.