성냥 스케쥴과 이벤트와 관련된 경쟁자를 찾을 수있는 여기에 제 complex (atleast i think it is complex)
조건이 있습니다.CakePHP multiple join JOIN findAll 조건 문제
이제 HTBTM
events_competitors
테이블과의 관계가 있는데, 여기에는 여러 이벤트에 여러 경쟁자 사용자 항목이 있습니다. 여기
, 내가 가입하고 잘 작동 competitors
와 events
관련 얻기 위해 joins
조건을 사용했지만, 나는 또한 (블랙 벨트를 확인) is_black
에 대한 추가 조건을 적용 할 및 is_adult
는
'EventCompetitor.is_black' => 0,
'EventCompetitor.is_adult' => 0,
두 조건 (is_black/is_adult)이 모두 0 인 경쟁 업체는 자격이 없다는 것을 의미하지만 동일한 경쟁 업체는 경쟁 업체가 아닌 결과를 초래합니다. 내가 JOIN
조건에 적용하는 일을 얻을 수 있도록하는 방법을
$matchdivisions = $this->Competitor->find("all" ,
array(
'conditions' =>
array(
'Competitor.status' => 1,
'Competitor.payment_completed' => 1,
'Competitor.weightgroup_id' => $current_matchsc['Matchschedule']['weightgroup_id'],
'Competitor.rank_id' => $current_matchsc['Matchschedule']['rank_id'],
'Competitor.degree_id' => $current_matchsc['Matchschedule']['degree_id'],
'Competitor.gender' => $current_matchsc['Matchschedule']['gender'],
),
'joins' =>
array(
array(
'table' => 'event_competitors',
'alias' => 'EventCompetitor',
'type' => 'left',
'conditions'=> array(
"AND" =>array(
'EventCompetitor.event_id = '.$current_matchsc['Event']['id'],
'EventCompetitor.is_black' => 0,
'EventCompetitor.is_adult' => 0,
)
),
)
),
'group' => 'Competitor.id'
)
);
어떤 생각, 그 결과에 적용됩니다
다음은 내 모든 찾기 조건이다.
감사합니다.
이 Competitor
를 선택
다음은 귀하의 심판에 대한 SQL 덤프입니다. id
, Competitor
. first_name
, Competitor
. last_name
, Competitor
. parent_name
, Competitor
. gender
, Competitor
. date_of_birth
, Competitor
. email_address
, Competitor
. weight
, Competitor
. weightgroup_id
, Competitor
. height
, Competitor
. rank_id
, Competitor
. degree_id
, Competitor
. photo
, Competitor
. school_id
, Competitor
. years_of_experience
, Competitor
. age
, Competitor
. tournament_id
, Competitor
. total_registration_fees
, Competitor
. address1
, Competitor
. address2
, Competitor
. city
, Competitor
. zip_code
, Competitor
. country_id
, Competitor
. state_id
, Competitor
. phone_number
, Competitor
. mobile_number
, Competitor
. payment_mode
, Competitor
. email_sent
, Competitor
. payment_completed
, Competitor
. status
, Competitor
. created
, Competitor
. modified
, Rank
. id
, Rank
. name
, Rank
. status
, Rank
. created
, Rank
. modified
, Tournament
. id
, Tournament
. tournament_name
, Tournament
. tournament_type
, Tournament
. tournament_date
, Tournament
. venue_name
, Tournament
. address1
, Tournament
.address2
, Tournament
. city
, Tournament
. zip_code
, Tournament
. country_id
, Tournament
. state_id
, Tournament
. created
, Tournament
. modified
, Country
. id
, Country
. name
, Country
. status
, Country
. created
, Country
. modified
, State
. id
, State
. country_id
, State
. name
, State
. short_name
, State
. status
, State
. created
, State
. modified
, Degree
. id
, Degree
. rank_id
, Degree
. name
, Degree
. status
, Degree
. created
, School
. id
, School
. name
, School
. address1
, School
. address2
, School
. city
, School
. zip_code
, School
. country_id
, School
. state_id
, School
. phone_number
, School
. owner_name
, School
. establishment_date
, School
. total_competitors
, School
. status
, School
. created
, School
. modified
, Transaction
. id
, Transaction
. competitor_id
, Transaction
. noncompetitor_id
, Transaction
. created
, Transaction
. modified
, Transaction
. mc_gross
, Transaction
. address_status
, Transaction
. payer_id
, Transaction
. address_street
, Transaction
. payment_date
, Transaction
. payment_status
, Transaction
. address_zip
, Transaction
. first_name
, Transaction
. address_country_code
, Transaction
. address_name
, Transaction
. custom
, Transaction
. payer_status
, Transaction
. address_country
, Transaction
. address_city
, Transaction
. payer_email
, Transaction
. verify_sign
, Transaction
. txn_id
, Transaction
. payment_type
, Transaction
. last_name
, Transaction
. address_state
, Transaction
. receiver_email
, Transaction
. item_name
, Transaction
. mc_currency
, Transaction
. item_number
, Transaction
. residence_country
, Transaction
. transaction_subject
, Transaction
. payment_gross
, Transaction
. shipping
, Transaction
. test_ipn
, Transaction
. Competitor
AS competitors
pending_reason
FROM는 ON EventCompetitor
AS 왼쪽 event_competitors 가입 (EventCompetitor
. event_id
= 3 AND EventCompetitor
. is_black
= 0을 EventCompetitor
. is_adult
= 0)가 LEFT Rank
ON (Competitor
AS ranks
가입.rank_id
= Rank
. id
) 왼쪽 (Competitor
ON Tournament
AS tournaments
가입. = Tournament
tournament_id
한다. id
) LEFT이 Country
ON (Competitor
AS countries
가입. = Country
country_id
한다. id
) LEFT이 State
AS (Competitor
ON을 states
가입. = State
state_id
한다. id
) LEFT이 degrees
가입 ON Degree
AS (Competitor
. degree_id
= Degree
. id
) 왼쪽 (Competitor
ON School
AS schools
가입. = School
school_id
있다. id
) LEFT JOIN transactions
AS Transaction
ON (Transaction
). competitor_id
= Competitor
. id
) WHERE Competitor
. status
= 1 AND Competitor
. payment_completed
= 1 AND Competitor
. weightgroup_id
= 13 AND Competitor
. rank_id
= 11 및 Competitor
. degree_id
= '0'AND Competitor
. gender
= '여성'GROUP BY Competitor
. id
다음은 왼쪽이 타이밍에서 쿼리 위의 조건을 조인 :이의 함유 성 행동을 사용해야
left JOIN event_competitors AS EventCompetitor ON (EventCompetitor.event_id = 3 AND EventCompetitor.is_black = 0 AND EventCompetitor.is_adult = 0)
코드를 포맷하고 디버그에서 SQL 덤프를 복사하십시오. – Headshota
확실 해요, 몇 분만 기다려주세요 ... –