spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Custom concatenated select and where like #202

Closed keevitaja closed 7 years ago

keevitaja commented 7 years ago

Hello!

I have columns firstname and name. I need to do a where statement where firstname and name are concatenated...

select concat(firstaname, ' ', name) as fullname where fullname ....

Is it possible to do this?

tuupola commented 7 years ago

I think it makes more sense to concatenate in the entity object.

public function fullname()
{
    return "{$this->firstname} {$this->lastname}";
}

However if preferred you can use ->query(...) to manually create a query with concatenation. Something like.

$foo = $mapper->query("SELECT CONCAT(firstname, ' ', lastname) AS fullname FROM foo WHERE id = 1");

Not sure how this would map to the entity though.

keevitaja commented 7 years ago

Ok, tnx!