cakephp habtm加入问题 [英] cakephp habtm join issue

查看:110
本文介绍了cakephp habtm加入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下表结构:

 活动(拳击,争吵等)
竞争对手参与比赛活动)
events_competitors(每个参赛者的选定活动将在这里)

我想要的是根据我的匹配时间表我想从计划表中找到竞争对手 ,其中每个竞争者将与他们在注册时选择的事件匹配。



我在使用查询查询,像这样:

  $ 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('EventCompetitor.event_id ='。$ current_matchsc ['Event'] ['id']),



);

在这里,我使用了 join ,因为我无法找到关系从 EventCompetitor 竞争者匹配

>

问题:单个匹配记录达到10次,因为 join ,而它应该是一次性的。



最早的回复将不胜感激。



提前感谢!



现在下一个级别,一旦这对我有效:



我有两个级别的条件检查,在 EventsCompetitors I想要看看,如果他们想与黑色皮带战斗或如果他们是未成年人,他们想与成年人战斗所以在这种情况下,我想看到这两个标志,在此基础上,我的条件将被更改,并将显示一个新的结果,我的其他显示。



再次感谢 stackoverflow

如果你只对一个记录感兴趣,并且总是确定其他是重复的,那么你可以使用find('first',...)。



如果你对多个不同的记录感兴趣,您可以添加到'group'=> array('')以汇总特定字段上的竞争对手,只返回一次?


I have table structure like below:

events (boxing, sparring etc)
competitors (users who are participating into diff events)
events_competitors (every competitor's selected events will go here)

Now what i want is, as per my match schedules i want to find competitors from schedules tables, where each competitors will be matching with events they have selected at registration time.

I'm using a find query something like this:

$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('EventCompetitor.event_id = '.$current_matchsc['Event']['id']),
                                                          ) 
                                                        )
                                )
);

Here, I have used joins because I am not able to find relations from EventCompetitor matching with Competitors and Events.

Problem: The single matching record comes 10 times, because of join while it should be single time only.

Earliest reply would be appreciated.

Thanks in advance!

Now a next level once this worked for me:

I have two levels of conditions check, in EventsCompetitors I want to see, if they want to have a fight with black belt or if they are minor and they want to have fight with adults so in this case, I want to see these both flags and on that basis, again my conditions will be changed and a new results will be displayed for my additional displays.

Kindly let me know, if sometime anyone have idea on this kind of stuffs with CakePHP.

Again a lot thanks to stackoverflow for their excellent services !

解决方案

If you are only interested in a single record and are always sure that the others are duplicates then you can use find('first', ...) instead.

If you are interested in multiple different records but you are getting multiples of each of those records you could add in a 'group' => array('') to aggregate the competitors on a specific field to only return them once ?

这篇关于cakephp habtm加入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆