protected function _after_select(&$resultSet, $options) { if (isset($options['attach'])) { foreach ($options['attach'] as $attach) { $this_ids = extract_field($resultSet, $attach[1]); $target = T($attach[0]); $that_map = $target->with($target->pk, 'in', $this_ids)->select_as_map(); // all the data needed in "that" table for ($i = 0; $i < count($resultSet); $i++) { $resultSet[$i][$attach[0]] = $that_map[$resultSet[$i][$attach[1]]]; } } } if (isset($options['fetch'])) { foreach ($options['fetch'] as $fetch) { for ($i = 0; $i < count($resultSet); $i++) { $target = T($fetch[0]); $resultSet[$i][$fetch[0]] = $target->with($fetch[1], $resultSet[$i][$this->pk])->select(); } } } if (isset($options['bridge'])) { foreach ($options['bridge'] as $bridge) { // alias for all the fields in bridge $that_name = $bridge[0]; $bridge_table_name = $bridge[1]; $this_field = $bridge[2]; $that_field = $bridge[3]; for ($i = 0; $i < count($resultSet); $i++) { $that_table = T($that_name); $bridge_table = T($bridge_table_name); $bridge_records = $bridge_table->with($this_field, $resultSet[$i][$this->pk])->select(); $bridge_results = array(); foreach ($bridge_records as $bridge_record) { $that_result = $that_table->with($that_table->pk, $bridge_record[$that_field])->find(); $that_result['_bridge'] = $bridge_record; array_push($bridge_results, $that_result); } $resultSet[$i][$that_name] = $bridge_results; } } } parent::_after_select($resultSet, $options); }