Help Me To Write Relation For My Three Tables

I have three tables "tbl_image","tbl_cars","tbl_flowers"

[color="#8B0000"]tbl_image[/color]

±-----±-------±------------+

| ide | Type | name |

|------±-------±------------+

| 5 | car | bmw0023.jpg |

| 10 | flower | rose8776.png|

| 12 | flower | lilly887.gif|

±-----±-------±------------+

[color="#8B0000"]tbl_cars[/color]

±-----±-------±------------+

| id | name | speed |

|------±-------±------------+

| 5 | BMW | 200Kmph |

±-----±-------±------------+

[color="#8B0000"]tbl_flowers[/color]

±-----±-------±------------+

| id | name | color |

|------±-------±------------+

| 10 | rose | white |

| 12 | lilly | orange |

±-----±-------±------------+

Please help me to write relation for model "Car" and "Flower"

Than u

is id in tbl_image primary key?

No…! "tbl_image" have no primary key… i need to pick images with matching type and id

By normal query we can select images of all car is


"SELECT tbl_image.name FROM tbl_image, tbl_cars where tbl_image.ide = tbl_cars.id AND tbl_image.Type = 'car'"

so your relation would be something like this:

in car model:





'images' => array(self::HAS_MANY, 'ImageModel', 'ide', 'condition'=>'type=car', 'select'=>'name'),




in image model:





'car' => array(self::BELONGS_TO, 'CarModel', 'ide', condition=>'type=car'),