Yii Framework Forum: How Do I Query A Table With Multiple Primary Key Values? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How Do I Query A Table With Multiple Primary Key Values? Rate Topic: -----

#1 User is offline   Huss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 26-November 11

Posted 20 January 2014 - 03:49 AM

In the example below $subscribersResources returns all matched records for subscriber id 1, lets say 20 matches.

Now I want to use the id_resources field in $subscribersResources to query another table called resources.


$subscribersResources = SubscribersResources::model()->findAll("id_subscriber='1'");
$resources = Resources::model()->findAll(????????????);



I'm a beginner in case it isn't obvious.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,342
  • Joined: 17-January 09
  • Location:Russia

Posted 20 January 2014 - 03:55 AM

It can be:

$subscribersResources = SubscribersResources::model()->findAll("id_subscriber='1'");
$resources = Resources::model()->findAll('id=:id', array('id' => $subscribersResources->id_resources));


But I'd check http://www.yiiframew...en/database.arr
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   Huss 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 26-November 11

Posted 20 January 2014 - 08:10 AM

View Postsamdark, on 20 January 2014 - 03:55 AM, said:

It can be:

$subscribersResources = SubscribersResources::model()->findAll("id_subscriber='1'");
$resources = Resources::model()->findAll('id=:id', array('id' => $subscribersResources->id_resources));


But I'd check http://www.yiiframew...en/database.arr


Thanks for the quick reply but yii logs and error: Trying to get property of non-object. If it helps this is the actual code.

  /**
     * @param string
     * @return string
     * @soap
  */  
  public function getResources($userInfo) {
  	    $response = array();
  		$userInfo = json_decode($userInfo, true);
  	     	     	   
  	    if(!$this->isValidAuthKey($userInfo['authKey'])){
			$response['error'] = 'Access denied';
			return json_encode($response);
  	    } else {
			$subscriber = Subscribers::model()->find("username='" . $this->getUserIdFromKey($userInfo['authKey']) . "'");
			$subscriberResources = SubscribersResources::model()->findAll("id_subscriber='" . $subscriber->id . "'");
			$resources = Resources::model()->findAll('id=:id', array('id' => $subscriberResources->id_resource));
			return json_encode($resources);
  	    }
  }

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users