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 8984959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:13:52+00:00 2026-06-15T21:13:52+00:00

Have two tables: Content id | text ———— 1 | text1 2 | text2

  • 0

Have two tables:

Content

 id |  text
------------
 1  | text1
 2  | text2
 3  | text3
 4  | text4

Photos

 id |  content_id |  src
-----------------------------
 1  |      1      |  img1.png
 2  |      1      |  img2.png
 3  |      2      |  img3.png
 4  |      3      |  img1.png

Trying to get content with left joined photos from third controller.

My code:

$oDBC = new CDbCriteria();
$oDBC->select = 't.*,p.*'; 
$oDBC->join = 'LEFT JOIN photos p ON t.id = p.content_id'; 
$oDBC->condition = 't.step_id = "'.$model->id.'"';

$content = Content::model()->find($oDBC);

In ContentController added function:

public function relations()
{
    return array('photos' => array(self::HAS_MANY, 'Photos', 'content_id');
}

But print_r($content) returns only content data, without photos data.

Like in this answer I tried:

print_r($content->photos);

but got Property "Content.photos" is not defined.

What am I doing wrong?

  • 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-06-15T21:13:53+00:00Added an answer on June 15, 2026 at 9:13 pm

    You have added the relations function in the wrong place. It should be added to the Content model, and not ContentController:

    class Content extends CActiveRecord {
    
        // ... other functions ...
    
        public function relations() {
            return array('photos' => array(self::HAS_MANY, 'Photos', 'content_id');
        }
    
    }
    

    If you have generated your model with Gii, then the relations function should already be there.

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

Sidebar

Related Questions

I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
I have two tables that make up a full text index of article content
I have two tables that have virtually identical content and very similar structure. They
I have two tables, content and images (and a ContentImages table for the one
If I have these two tables: <table> <tr> <td>Small Length Content</td> </tr> </table> <table>
I have two tables that relates 1:n content --------- - id - title -
supposing that I have two tables with same 3 columns: ID (int, identity), text
I have two tables here - one is in UTF and holds Arabic text
I have these three tables, page table page_id page_title 1 a content table content_id
I have two table cells, with dynamic content. Table cell one works fine, when

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.