I come across this a lot, and have always been curious if there is better way.
Consider this (example only, assume an OO query builder)
class Dogs extends Pets {
public function getAll() {
return $this->parseRows($this->db->get('dogs'));
}
public function getBig() {
return $this->parseRows($this->db->get('dogs')->where('size', '>', 10));
}
public function getSmelly() {
return $this->parseRows($this->db->get('dogs')->where('smell', '=', 'bad'));
}
private function parseRows($rows) {
foreach($rows as &$row) {
$row['id'] = (int) $row['id'];
$row['categoryName'] = Categories::getById($row['categoryId']);
}
return $rows;
}
}
Basically, I need to use a lot of database queries, but they all need to go through a post-processing to assign things to them. I have been using a pattern like above.
Is this the best practice way to do this?