model inheritance - list all objects of depth of inheritance

How could I list all products in the example? The implementation of product as CModel is OK or?

The data is saved in 1 table per class, but the tables of the extended ones just contain their own attributes.

I am not sure how to use in Yii a database without ActiveRecord, all the examples are with it, there are no examples concerning practical use of DAO.

And where to build the criterias, it is often done in the controller, why not in the model?

Example:


abstract class product extends CModel

{

public id;

public price;

}

class car extends product

{

public hp;

}

class computer extends product

{

public ram;

}

tbl_product: id price

tbl_car : hp product_id

tbl_computer : ram product_id

Why do you want to use DAO instead of CActiveRecord?

It is better to use composition in your case, at least if you ask me. But somehow I feel you should delve into Yii by doing the blog tutorial and so on, because that is an advanced technique.

Regards,

composition: what do you exactly think of? all in one class?

But that was just an simple example, I want to create a product catalog with very many different attributes.

When using CActiveRecord all data would be in one table, due to the fact, that I have many different attributes that would not be very performant.

I have already read the guide and most parts of the blog tutorial, but the tutorial just mentions ActiveRecord concerning databases.

for anyone who interest in product model design you can read at dynaModel ,

@yiqing95

Thanks, that is not bad ;)

However it confuses me a bit, that I should have just 1 class, because inheritance is in OOP always mentioned, but in this case it would probably just cause problems like the one above or has someone an idea how to manage it with inheritance?

No, I think it doesn’t help me, because I have pretty many attributes, but they in general they are not dynamic, means the overall list of attributes will always be nearly the same.

Any other idea how to handle it, maybe I need any class, that manages all the objects?

I liked this article very much about class table inheritance, although I haven’t implemented that concept yet

There’s also a wiki on STI

i never say that suit you :lol: ; it just related (about product table design ) , you can also search form stackoverflow with product table schema ; and i think this one is not bad Database Design Strategy : Product Table on E-Commerce System (EAV, Class Table Inheritance or Concrete Table Inheritance)

and as bennouna point , you should read this wiki singleTableInheritance in Yii

Single-Table-Inheritance would be working, but I don’t like it.

A Class-Table-Inheritance is in some Stackoverflow discussions recommended, as I did in my first post and I would like to use it for the DB.

However the problem is how to use it in Yii, maybe I don’t even need an inheritance structure in Yii, but just a single class?

OK, but what to do if I wanted to list ALL items of the catalog of all subclasses?