Yii Framework Forum: Select Inner Join - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Select Inner Join Rate Topic: -----

#1 User is offline   mentorq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 105
  • Joined: 26-June 13

Posted 16 September 2013 - 02:59 AM

Mógłby mi ktoś pomóc, ponieważ nie wiem jak użyć tego warunku w swoim projekcie...??

SELECT fee.feeId,fee.feeDesc, pupil_has_user.user_userId
FROM fee
INNER JOIN pupil_has_user
ON fee.pupil_has_user_id=pupil_has_user.pupil_pupilId


Próbowałem, ale nie działa:
$criteria = new CDbCriteria;
            $criteria->select = 'fee.*, pupilHasUser.user_userId ';
            $criteria->join = 'JOIN pupilHasUser on fee.pupil_has_user_id= pupilHasUser.user_userId';
            $resultSet    =    Fee::model()->findAll($criteria);

0

#2 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 16 September 2013 - 09:24 AM

Czemu nie działa? Jeśli nie zmieniałeś domyślnego alias to powinieneś dać 't.*' zamiast 'fee.*'.
Don't be a dick.
0

#3 User is offline   aztech 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 12-December 08
  • Location:Poland

Posted 17 September 2013 - 01:52 AM

Czy zadziała zależy od wersji Yii, której używa. Od wersji 1.1.13 nastąpiła pewna zmiana w aliasach, którą wyjaśnia następujący wpis z instrukcji aktualizacji- Criteria modification in CActiveRecord::beforeFind() did not apply to the query when model was loaded in a relational context.

Quote

Since version 1.1.13 changes to query criteria made in beforeFind() now also apply to the query when model is loaded in a relational context. The main problem here is that you can not use the `t`-alias for your table anymore, you have to change your code to use the table alias currently in use as this is different in relational context. You can get that alias by calling `$this->getTableAlias();` in your active record class or `$this->owner->getTableAlias()` in behavior context. Example: $criteria->condition = 't.myfield = 1'; You need to change that to: $alias = $this->owner->getTableAlias(); $criteria->condition = $alias.'.myfield = 1';

I'm not complete idiot... some parts are missing!
0

#4 User is offline   mentorq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 105
  • Joined: 26-June 13

Posted 17 September 2013 - 04:27 AM

Trochę to zmodyfikowałem i zadziałało

$criteria = new CDbCriteria;
                $criteria->select = 't.*, tu.* ';
                //$criteria->join = 'JOIN pupilHasUser on fee.pupil_has_user_id= pupilHasUser.user_userId';
                $criteria->join = 'JOIN pupil_has_user as tu ON tu.pupil_pupilId = t.pupil_has_user_id';
                $criteria->addCondition("t.pupil_has_user_id ='8'");
                $resultSet    =    Fee::model()->findAll($criteria);


Mówiąc zadziałało mam na myśli, że się nie wysypuję. Teraz czy mogłby mi ktoś pomóc jak wyświetlić połączone dane z tabeli pupil_has_user ?? Póki co osiągam:

$criteria = new CDbCriteria;
                $criteria->select = 't.*, tu.* ';
                $criteria->join = 'JOIN pupil_has_user as tu ON tu.pupil_pupilId = t.pupil_has_user_id';
                $criteria->addCondition("t.pupil_has_user_id ='4'");
                $resultSet    =    Fee::model()->findAll($criteria);
                //print_r($resultSet);
                
                $dd_data = array();
                
                //echo $resultSet->pupil_pupilId;
                foreach($resultSet as $result)
                {
                    echo $dd_data[$result->feeId] = 'Numer płatności '.$result->feeId.' Kwota: '.$result->number1;  
                    echo '<br />';
                    
                }


Posted Image

Nie wiem jak dołączyć do tego dane z drugiej tabeli ...

np. pupilFullName, pupil_pupilId, user_userId
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users