Hey! I’m having trouble getting traction on making this query using AR. I’ve read docs, and I’ve searched forums, but nothing I’ve seen quite works.
I’m trying, through AR to get a property of a record that is two tables away.
Page table has collectionID
Collection table has suiteID
Suite has ‘title’, which is what I want.
There is one suite which has many collections, and each collection has many pages. Each collection belongs to one suite. Each page belongs to one collection.
In the page model, there is a relation that was automatically generated by gii based on my FKs:
‘collection’ => array(self::BELONGS_TO, ‘Collection’, ‘collectionId’),
and I was able to use collection.suiteId in a CGridView display. Based on what I saw in the "Relational Query with through" section of the guide, I thought that I would be able to create the following relation:
‘suite’=>array(self::HAS_ONE,‘Suite’,array(‘suiteId’=>‘id’),‘through’=>‘collection’),
and use suite.title in a CGridView display. I get the following error:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘collection.collectionId’ in ‘where clause’. The SQL statement executed was: SELECT suite
.id
AS t1_c0
, suite
.title
AS t1_c1
, suite
.permissions
AS t1_c2
, suite
.description
AS t1_c3
, suite
.thumbnail
AS t1_c4
FROM Suite
suite
LEFT OUTER JOIN Collection
collection
ON (collection
.suiteId
=suite
.id
) WHERE (collection
.collectionId
=:ypl0)
I’m really not sure where it’s getting “collection
.collectionId
=:ypl0”
Should I be going about this in an entirely different way? Am I completely incorrect about the problem? Is it just something that I’m idiotically overlooking? If you could be as specific as possible, I’d really appreciate it. I’ve bean a procedural Perl and PHP developer for a while, and I’m attempting to get OO programming, MVC, AR and Yii all at once. Really loving some of the functionality, but some other stuff I’m finding, even after reading the documentation as a noob, to be a bit opaque.
Once again, I’m a nood and I really appreciate your help. I fully intend on spending plenty of time on the forums to answer questions once I get my leet skillz.