Skip to content
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

Improve DataMapper wasModified() behavior #2

Open
R4PH1 opened this issue Jan 5, 2021 · 1 comment
Open

Improve DataMapper wasModified() behavior #2

R4PH1 opened this issue Jan 5, 2021 · 1 comment

Comments

@R4PH1
Copy link

R4PH1 commented Jan 5, 2021

Hi,

love your database libraries. Unfortunately I cannot do a Pull request.

I have a few issues to report which you might be interested in:

Issue 1:
Opis\ORM\Core\DataMapper->setColumn()
When calling the function with the same value as already set previously I expect $orm->wasModified() to return false not true.

My "dirty fix" looks like that:

    public function setColumn(string $name, $value)
    {
           .....
           if (isset($this->rawColumns[$name])){        
                 if($this->rawColumns[$name] == $value){                   
                      return;
                }
           }
    
           $this->modified[$name] = 1;
           unset($this->columns[$name]);
           $this->rawColumns[$name] = $value;
    }

Issue 2:
some parts of the IDE auto completion do not work especially when querying from the orm object:
(Using netbeans 12.2)
$orm->query(test::CLASS)-> this works for most cases, get() does not work.
$orm->query(test::CLASS)->withSoftDeleted(true)-> limited only, no get() etc.
$orm->query(test::CLASS)->where(...)->like(...)-> not working at all

I found out changing some traits to public instead of protected does the thing. Don´t know if this is a change you want to do or not.

If nothing of this is in your interest, just close the issue.

Br

@msarca
Copy link
Member

msarca commented Jan 5, 2021

Hi, thanks for your feedback.

The behavior is correct even though the method's name might be a little bit misleading, and the documentation doesn't help either. When you set a value on an entity object, the object is considered to be modified, regardless of the value you set. We have good reasons for keeping things the way they are.

My "dirty fix" looks like that:

By not using the strict comparison operator, type juggling will occur, which might lead to some serious bugs or security issues.

var_dump("8ball" == 8); //bool(true)

We are using PHPStorm as our default IDE, and the autocompletion is stellar. Before switching to PHPStorm, we were also using Netbeans, but now we would never switch back. I can imagine that the coding experience is poor without proper autocompletion, but this is something that Netbeans must fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants