PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

[FIXED] Relational Active record with BELONGS_TO in Yii

 January 30, 2022     php, yii     No comments   

Issue

I have 2 tables called Member and MemberResume.

MemberResume references Member on the key memberid.

In the MemberResume model the relation is set like this:

'member' => array(self::BELONGS_TO, 'Member', 'memberid')

I am trying to create a model in this manner.

$model=Memberresume::model()->with('member')->findAllByAttributes(array('memberid'=>$id));

But in the model I am not able to access the attributes of member table like membername etc., though the relational query generated seems to consider the relationship.

Any idea why?


Solution

Try this instead:

$model=Memberresume::model()->findAllByAttributes(
  array('memberid'=>$id), // $attributes
  array('with'=>'member') // $condition (string, array or Criteria object, I think)
);

findAllByAttributes accepts a second "condition" parameter you can add your "with" clause to. Doing it this way should join the Member table so you can access it's attributes.



Answered By - thaddeusmt
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing