Two models are returned as Zend_Db_Select
objects.
Then, I need to join them and fetch data together at once.
class Model_User extends Abstract_Model {
public function sqlUser() {
return $this->select(array(
'user_id', 'user.name', 'user.login', 'address.street', 'city.city_id', 'city.city_name','region.region_id', 'region.region_name'
))
->joinUsing('address','address_id','') ->join('city', 'city.city_id = address.city_id', '')
->join('region', 'region.region_id = city.region_id', '');
}
}
class Model_Technics extends Abstract_Model{
public function sqlList() {
return $this->select()
// here some more sql
->joinUsing('catalog_model','model_id','');
}
}
Then I need some where else fetch sqlList with all info for every user. I dont whant to duplicate all code, I just want to join sql from User model through join
You could iterate through the "sections" of zend_db_select (columns,from,joins,where) and figure a way to append them to the other query, but I wouldn't suggest it.
An alternative might be to have a "join" method on the model you're joining to, which will take your select object and run the join method(s) on it. It would, of course, depend on the table(s) already available in the select object already. Or that method might just pass back a structure defining how to join to the join-model's table, which your primary model can decide what to do with it.
There are a ton of solutions, but there's no really easy way to just jam two zend_db_select objects together without some extra logic between them. The main missing piece would be relationship information between the two models.
I know this isn't a full blown answer (as I can't comment yet), but hopefully it will point you to a path that sounds usable.