Yii Framework Forum: Cstatrelation With Complex Foreign Key - Yii Framework Forum

Jump to content

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

Cstatrelation With Complex Foreign Key CStatRelation doesn't appear to support array() values for foreign Rate Topic: -----

#1 User is offline   mclemay 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 13-November 12

Posted 15 December 2012 - 08:42 AM

I have this sort of situation:

create table post(
    postid INT NOT NULL PRIMARY KEY
   ,parentpostid INT REFERENCES post(postid)
)
create table post_property(
    propertyid INT NOT NULL PRIMARY KEY
   ,postid INT NOT NULL REFERENCES post(postid)
   ,key VARCHAR(128) NOT NULL
   ,value TEXT
)


I want to do this in my Model's relations() array:

'overallChildCount' => array(
    self::STAT
   ,'Post'
   ,array('parentpostid','postid')
)
,'publishedChildCount' => array(
    self::STAT
   ,'Post'
   ,array('parentpostid','postid')
   ,'join' => 'INNER JOIN '.PostProperty::Model()->tableName().' AS pp USING(postid)'
   ,'condition' => 'pp.key = \'status\' AND pp.value = \'published\''
)


i.e., what I'm trying to do in publishedChildCount is to get the count of children of a post with a status of published. When I do:

$post = Post::Model()->findByPk(....);
$post->getRelated('publishedChildCount');


I get:

preg_match() expects parameter 2 to be string, array given (.... framework/db/ar/CActiveFinder.php:1363)


The overallChildCount relation gives me the same result when I call getRelated().

It appears that for CManyManyRelation types, it deals with foreignKeys that are arrays explicitly, but it doesn't do this for CStatRelation types. Am I missing something here?

Thanks - Matt
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