Hi,
I’m kind of starting with yii and I really like it! While making one of my first apps I keep hitting this problem:
I have a generic database structure for lets say property information. Like this:
CREATE TABLE properties (
id INT(11) NOT NULL,
item_id INT(11) DEFAULT NULL,
prop VARCHAR(255) DEFAULT NULL,
value VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id)
);
INSERT INTO properties VALUES
(1, 1, 'color', 'blue'),
(2, 1, 'size', 'large'),
(3, 2, 'color', 'orange'),
(4, 3, 'size', 'small'),
(5, 4, 'color', 'violet'),
(6, 5, 'color', 'green');
I make use of an extension that requires the table to be pivoted as a CActiveRecord model:
SELECT
item_id,
MAX(IF(prop = 'color', value, NULL)) AS color,
MAX(IF(prop = 'size', value, NULL)) AS size
FROM
properties
GROUP BY
item_id;
+---------+--------+-------+
| item_id | color | size |
+---------+--------+-------+
| 1 | blue | large |
| 2 | orange | NULL |
| 3 | NULL | small |
| 4 | violet | NULL |
| 5 | green | NULL |
+---------+--------+-------+
The input of the extension needs to be in the format of the above printed table as CActiveRecord.
So my question is: is it possible to make a generic model out of the stated query as input for my extension?
In reality my problem is a bit more complicated as the query I want to use makes use of 4 joined tables to gather the column names and associating data.
Thanks in advance!
Marijn