/ / Ako získať viac záznamov, aby sa spojili do jednej tabuľky alebo použili obsahovať s podmienkami? - mysql, cakephp, pripojte sa

Ako získať viac záznamov do jednej tabuľky alebo použiť obsahovať s podmienkami? - mysql, cakephp, pripoj sa

Používam cakePHP 2.6.4.
Mám dve tabuľky AgentChat a AgentChatMember.
AgentChat má mnoho AgentChatMember,
AgentChatMember Patrí AgentChat.

AgentChat majú: id, team_id, agent_chat_member_count polí.
AgentChatMember majú: id, agent_chat_id, user_id polí.

Chcem to nájsť AgentChat podľa chat_team_id a agent_chat_member_count,
a AgentChatMember ako obsahovať s user_id podmienky.

    $options["contain"] = array("AgentChatMember");
$options["conditions"]["AgentChat.agent_chat_member_count"] = count($user_ids);
$options["conditions"]["AgentChat.chat_team_id"] = $chat_team_id;

$res = $this->AgentChat->find("first", $options);

a $res je:

     "AgentChat" => array(
"id" => "1",
"agent_message_count" => "0",
"agent_chat_member_count" => "2",
"chat_team_id" => "14",
"created" => "2015-05-06 09:52:31",
"updated" => "2015-05-06 09:52:31"
),
"AgentChatMember" => array(
(int) 0 => array(
"id" => "1",
"agent_chat_id" => "1",
"user_id" => "26",
"created" => "2015-05-06 09:52:31"
),
(int) 1 => array(
"id" => "2",
"agent_chat_id" => "1",
"user_id" => "21",
"created" => "2015-05-06 09:52:31"
)
)

Týmto dosiahnem to, čo chcem, okrem skutočnosti, ktorú nemôžem nastaviť user_id podmienku AgentChatMember ako toto: $options["conditions"]["AgentChatMember.user_id"] = $user_ids;

Keď používam spájania namiesto toho, aby som mohol obsahovať, môžem nastaviť podmienky user_id, ale dostanem výsledok takto:

(int) 0 => array(
"AgentChat" => array(
"id" => "1",
"agent_message_count" => "0",
"agent_chat_member_count" => "2",
"chat_team_id" => "14",
"created" => "2015-05-06 09:52:31",
"updated" => "2015-05-06 09:52:31"
),
"AgentChatMember" => array(
"id" => "2",
"agent_chat_id" => "1",
"user_id" => "21",
"created" => "2015-05-06 09:52:31"
)
),
(int) 1 => array(
"AgentChat" => array(
"id" => "1",
"agent_message_count" => "0",
"agent_chat_member_count" => "2",
"chat_team_id" => "14",
"created" => "2015-05-06 09:52:31",
"updated" => "2015-05-06 09:52:31"
),
"AgentChatMember" => array(
"id" => "2",
"agent_chat_id" => "1",
"user_id" => "26",
"created" => "2015-05-06 09:52:31"
)
),
...

Je možné dosiahnuť, aby sa viac záznamov spojilo do jednej tabuľky alebo obsahovalo podmienky, ktoré sú v ňom uvedené?
Ako to môžem dosiahnuť?

odpovede:

0 pre odpoveď č. 1

Môžete prejsť podmienky obsahovať: -

$res = $this->AgentChat->find(
"first",
array(
"contain" => array(
"AgentChatMember" => array(
"conditions" => array(
"AgentChatMember.user_id" => $userIds
)
)
),
"conditions" => array(
"AgentChat.agent_chat_member_count" => count($userIds),
"AgentChat.chat_team_id" => $chatTeamId
)
)
);

Rovnako ako stranou, mali by ste byť skutočne ťava, ktorá ukladá vaše premenné v CakePHP. Pozrite si Štandardy kódovania v dokumentácii.