Hello out there,
I have a very unusual ActiveRecord problem while creating a new application using the Yii framework.
Problem is, that the application has a very unclean database layout like this:
As you can see the database isn't normalized very well. In a clean database, there should be 3 tables (news, flag, flag2news), but there are only 2 tables like this ones.
Now i want to create the following model structure (only reading is necessary, writing to the database is not needed in this case):
A news has many flags in this case.
To achieve this, the News model should retrieve its values from table 1 and group by newsId. It shouldn't retrieve the "flagId" column. Then the relation should join on the flag table using the "flagId".
I don't know how I can force the News model to do grouping by default. Is there any option to achieve this?
The next question is how to realize the relation if there is no flagid anymore. A join to the the news table and another join to the flag table is an option. I will do it this way if it works.
But the main problem is how to do default grouping in the news model.
Maybe you can help me solve the problem.
Thanks in advance,
Changing the database layout is not an option is this case