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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:17:07+00:00 2026-05-29T06:17:07+00:00

I have a very simple relation defined as follows ( aId and bId are

  • 0

I have a very simple relation defined as follows (aId and bId are the primary keys for each table).


class A extends CActiveRecord
{
    // @var int32 $aId
}

class B extends CActiveRecord
{
    // @var int32 $bId
    // @var int32 $aId

    public function relations()
    {
        return array(
            'a'=>array(self::HAS_ONE, 'A', 'aId'),
        );
    }
}

As long as bId <= 5, I can access A through $bModel->a without any problems. What’s strange is for bId > 5, $bModel->a is null. I’ve checked $bModel->aId for bId > 5 and the foreign key is correct. I can even access A with $aModel = A::model()->findByPk($bModel->aId);. I can also manually edit my bIds in the database table, which produces the same result.

I have no idea what’s causing the relation to fail for primary key’s greater than five. Any suggestions for troubleshooting? I’m at a loss.

EDITED

It turns out I wasn’t using the relation properly. I should have used BELONGS_TO.


class B extends CActiveRecord
{
    // @var int32 $bId
    // @var int32 $aId

    public function relations()
    {
        return array(
            'a'=>array(self::HAS_ONE, 'A', 'aId'),
        );
    }
}

HAS_ONE was causing B to use bId to index A. Since I had five instances of A in my database that worked for bID < 5

  • 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-29T06:17:08+00:00Added an answer on May 29, 2026 at 6:17 am

    Enable query logging in your application config to see what exactly is happening.
    Do you get any results when manually running those queries?

    'components' => array(
    
        'db' => array(
            (..)
            'enableParamLogging' => true,
        ),
    
        'log' => array(
            'class' => 'CLogRouter',
            'routes' => array(
                // Show log messages on web pages
                array(
                    'class' => 'CWebLogRoute',
                    'categories' => 'system.db.CDbCommand', //queries
                    'levels' => 'error, warning, trace, info',
                    //'showInFireBug' => true,
                ),

    (I’d post this as a comment rather than an answer, but it seems I can’t)

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

Sidebar

Related Questions

I have a very simple table(mapped as AuthToken class), consisting of a string ('token'),
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple mapping like: public abstract class EntityMap<TEnt, TId, TDto> :
i have very simple problem. I need to create model, that represent element of
I have very simple window where I have 2 buttons - one for cancel,
I have a very simple question regarding BSTs. I have seen multiple definitions of
I have some very simple javascript code that looks like this: var newWindow =
I have this very simple code: #include <stdio.h> #include <stdlib.h> int maxArr(int *arr) {
I have a very simple problem which requires a very quick and simple solution
I have a very simple WPF application in which I am using data binding

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.