Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:30:02+00:00 2026-05-26T02:30:02+00:00

Image describing the tables -> https://i.stack.imgur.com/ki2YP.jpg Each of the tables is a model. Main

  • 0

Image describing the tables -> https://i.stack.imgur.com/ki2YP.jpg

Each of the tables is a model.

Main model which shows through CGridView is “RegularTask”.

Now I need it to display fields from “YearlyTask” in the same row.

“hp_id” and “up_id” are FK (foreign keys) in both tables.

I tried to set the relations() in the RegularTask model like this:

'arp' => array(self::BELONGS_TO, 'YearlyTask', 'hp_id, up_id'),

Then I try to display the “is_sent” and “is_reported” fields from YearlyTask by using “arp.is_sent” and “arp.is_reported”, but nothing shows up (not even error). While data from RegularTask displays normally.

What am I doing wrong?

Here is a snippet from the dataprovider..

<?php
$dataProvider=new CActiveDataProvider('RegularTask', array(
    'criteria'=>array(
        'condition'=>'t.id_id=' . $model->id,
        'order'=>'t.created DESC',
        'with'=>array('arp'),
    ),
    'pagination'=>array(
        'pageSize'=>10,
    ),
));

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'comment',
        'arp.is_sent'
    ),
));
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:30:03+00:00Added an answer on May 26, 2026 at 2:30 am

    Foreign key in one table must be primary key in linked table.
    If you look into SQL statement created by Yii with your structure, you will see something like this (simplified):

    SELECT `t`.*, `arp`.* FROM `RegularTask` `t` LEFT OUTER JOIN `YearlyTask` `arp` ON (`t`.`hp_id`=`arp`.`id`) AND (`t`.`up_id`=`arp`.`id`)
    

    As you can see, what it looks for is that both RegularTask.hp_id and RegularTask.up_id have same value as YearlyTask.id which isn’t correct.
    You have several solutions. One of them is create new column in RegularTask like yt_id which will be foreign key for YearlyTask.id and in my opinion it’s the best solution.

    Otherwise you can delete your primary key column id in RegularTask table and make hp_id and up_id as complex primary key. In this case you can use the way you tried before, but as i don’t know your full db structure i can’t guarantee that it’s good solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Image describing the problem http://img215.imageshack.us/img215/3725/20100314235127schedule2.jpg I hope the image above can explain what I
The image above is from Wikipedia's entry on AVL trees which Wikipedia indicates is
I am trying to marshal with jaxb an object which contains an Image, and
I am trying to marshal with jaxb an object which contains an Image, and
Let me start off by describing my situation. I have a main view that
Image shows the buttons on my UI in vb.net All these buttons are having
Image the following scenario, You have 10 Java applications accessing a database server Each
My custom post type is for describing companies. Each post will require 4 images
I am trying to marshal with jaxb an object which contains an Image, and
I am trying to marshal with jaxb an object which contains an Image, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.