Level-2 / Maphper

Maphper - A php ORM using the Data Mapper pattern
BSD 2-Clause "Simplified" License
52 stars 7 forks source link

Wrap filter issue #45

Closed solleer closed 6 years ago

solleer commented 7 years ago

Currently the following private function does not work as intended in Maphper

//Allow filter(['user' => $user]) where $user is an object instead of
//filter(['userId' => $user->id])
private function wrapFilter() {
    foreach ($this->settings['filter'] as $name => $value) {
        if (isset($this->relations[$name])) {
            $filter = $this->relations[$name]->getFilter($value);
            $this->settings['filter'] = array_merge($this->settings['filter'], $filter);
            unset($this->settings['filter'][$name]);
        }
    }
}

getFilter does not work on the relation classes

TRPB commented 6 years ago

Do you have a test case or some sample code that triggers this bug?

solleer commented 6 years ago

getFilter does not exist or returns an empty array for all the relations so there is no way that it works

TRPB commented 6 years ago

I'm not sure why I'd commented it out. I've uncommented the lines and applied the filter. All the code was there for one-to-one relationships. It doesn't really make any sense for other relationship types.

This will cause a problem if you have a column name the same as the relationship name, but that will consistently cause issues in maphper.