/** * Merges info from the other EEM_Related_Model_Info_Carrier into this one. * @param EE_Model_Query_Info_Carrier $other_model_query_info_carrier */ public function merge($other_model_query_info_carrier) { if ($other_model_query_info_carrier && !$this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) { $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included(); $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier); $this->_join_sql .= $other_model_query_info_carrier->_join_sql; } //otherwise don't merge our data. //yes, this means that we must immediately merge any model data into our grand list //as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier //which is carrying info from two models WHERE one is already included but the other is NOT }
/** * Privately used by _extract_related_model_info_from_query_param to add a join to $model_name * and store it on $passed_in_query_info * @param string $model_name * @param EE_Model_Query_Info_Carrier $passed_in_query_info * @param string $original_query_param used to extract the relation chain between the queried model and $model_name. * Eg, if we are querying Event, and are adding a join to 'Payment' with the original query param key 'Registration.Transaction.Payment.PAY_amount', * we want to extract 'Registration.Transaction.Payment', in case Payment wants to add default query params so that it will know * what models to prepend onto its default query params or in case it wants to rename tables (in case there are multiple joins to the same table) * @return void */ private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { $relation_obj = $this->related_settings_for($model_name); $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); //check if the relation is HABTM, because then we're essentially doing two joins //If so, join first to the JOIN table, and add its data types, and then continue as normal if ($relation_obj instanceof EE_HABTM_Relation) { $join_model_obj = $relation_obj->get_join_model(); //replace the model specified with the join model for this relation chain, whi $relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain); $new_query_info = new EE_Model_Query_Info_Carrier(array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); $passed_in_query_info->merge($new_query_info); } //now just join to the other table pointed to by the relation object, and add its data types $new_query_info = new EE_Model_Query_Info_Carrier(array($model_relation_chain => $model_name), $relation_obj->get_join_statement($model_relation_chain)); $passed_in_query_info->merge($new_query_info); }