title: Yii relation for composite key as foreign key and get sum
body: <p>I have three tables (Booking,Ticket,Trainee_grant) with below structure</p>
  
  <pre><code>    Booking
         id (primary key)
         name  
      Ticket
        booking_id int,
        seq int,
        name
        address,
        primary key (booking_id,seq)
        CONSTRAINT `fk_booking` FOREIGN KEY booking_id reference Booking
     Trinee_Grant
        id int 
        booking_id
        seq
        amount
        CONSTRAINT `fk_trainne_ticket_grant` FOREIGN KEY (`booking_id`, `seq`) REFERENCES `ticket` (`booking_id`, `seq`)   ;
  </code></pre>
  
  <p>I have relation for Ticket_tb and trainee_grant_tb as below.</p>
  
  <p>Ticket model</p>
  
  <pre><code>public function relations() {
          return array(
              'booking' =&gt; array(self::BELONGS_TO, 'Booking', 'booking_id'),
              'traineeGrants' =&gt; array(self::HAS_MANY, 'TraineeGrant', 'booking_id'),
              'traineeGrants1' =&gt; array(self::HAS_MANY, 'TraineeGrant', 'seq'),
          );
      }
  </code></pre>
  
  <p>and TraineeGrant model as below</p>
  
  <pre><code>    public function relations() {
           return array(
             'bookingSeq' =&gt; array(self::BELONGS_TO,'Ticket','booking_id,seq'),
         );
       }
  </code></pre>
  
  <p>How can i add relation in Booking so that i can get SUM(amount) of all booking_id from trainee_grant table ?</p>
  
  <p>I tried with below but gives me error.</p>
  
  <p>Booking Model</p>
  
  <pre><code>$relations['amountTraineeGrant'] = [
                      self::STAT,
                      'TraineeGrant',
                      'booking_id',
                      'select' =&gt; 'SUM(amount)',
                  ];
  </code></pre>
  
  <p>it gives me error as below</p>
  
  <pre><code>The relation "amountTraineeGrant" in active record class "Booking" is specified with a foreign key "booking_id" that does not point to the parent table "booking".  
  </code></pre>
  
  <p>Am i missing something ..i am not able to find error .Plz help me </p>