simple-orm icon indicating copy to clipboard operation
simple-orm copied to clipboard

Support for "non-string" commands in update.

Open angedelamort opened this issue 6 years ago • 0 comments

Hello,

I really like your simple ORM (similar to what I did in the past, but with a different phylosophy),

It took me 15 minutes to figure out why my command wasn't working:

// What I want:
UPDATE invite SET field = field - 1 WHERE ( id = ? );

// What it was printing
UPDATE invite SET field = 'field - 1' WHERE ( id = ? );

so after thinking a little bit, I though of an idea. Not sure if you want to introduce that into you code but I didn't want to change your sources. Also, it might be interesting to put in your README.

So here's my quick solution:

class StringWithoutQuote {
    private $value;

    public function __construct($value) {
        $this->value = $value;
    }

    public function __toString() {
        return $this->value;
    }
}

Now you can write something like that:

Invite::query()->
    update(['field' => new StringWithoutQuote('field - 1')])->
    where()->andFilter('id', '=', $id)->
    execute();

thanks

angedelamort avatar Mar 12 '19 00:03 angedelamort