model - Find() one of each matching field CakePHP -
trips hasmany legs
airports has no associations
how can find cheapest trip each destination airport using cakephp?
right now, thing can think of foreach through array of airports. require hundreds of queries database (which think not fastest way of doing it).
function getcheapesttrip($origin){ $airports=$this->airport->getairports(); foreach($airports $airport): $cheapest_flights=$this->trip->find('first', array( 'conditions'=>array('leg.origin'=>$origin, 'min(trip.price) price'), 'fields'=>array('trip.origin','price','leg.destination','leg.depart','leg.arrive'), 'recursive'=>2, )); endforeach; } }
also, think data type stuff should in model per cakephp conventions (fat models, skinny controllers). read call different model's function such getairports can use loadmodel found in cakephp's controller method section. how should 1 model's data/model function anothers?
thanks!
the answer second question, "how load model within model?" can found here.
Comments
Post a Comment