Skip to content

Support for "non-string" commands in update. #2

@angedelamort

Description

@angedelamort

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions