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:
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 LEFT OUTER JOIN
collection ON (
id) WHERE (
I’m really not sure where it’s getting “
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.