I have the following database scheme.
Subject - party to a legal relationship;
Company - a company as such a party (let INN, OGRN be some attributes needed for companies);
Person - a person as such a party.
Subject can be either a Person or Company. Type of the Subject is defined by idType column that is a FK to SubjectType dictionary table.
Then, I want to have a page with a CGridView and the following columns: Sign (‘C’ for Company, ‘P’ for Person), Name (“Name Surname” in case of Person or “ShortName” in case of company), Country, INN, OGRN. Also a search form needed where one could select records by the type of a Subject, INN, Name, Sex, OGRN. In order to exclude Persons or Companies from the search results two checkboxes are needed: “Include companies”, “Include persons”.
So, I’ve found /wiki/281/searching-and-sorting-by-related-model-in-cgridview/ recipe. The recipe offers to declare additional attributes in a model for the Subject table. These attributes would receive user inputs (for search) and be shown in a grid. The search method shoul also be modified to add new criterias using relations between tables.
What are the disadvantages I see? In fact, in the Subject model I need to duplicate attributes that are already defined in models Person and Company. Also, for the new attributes I need to define AttributeLabels that are, again, alredy defined in models Person and Company.
I’ve also found /wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models recipe. The recipe offers to create all the models in a controller and pass them to a view. In this case I am confused, what the grid should be binded to (what’s the setting for ‘dataProvider’ attribute). I’ve came up to an idea to create a model that would incapsulate models Company, Person and Subject, define the search() method, to which the grid will be binded. It’s not clear for me how to organise the search() metod so to operate multiple models at once.
Useful hints and links are appreciated. Thank you in advance.
[size=“1”]P.S. It’s my first message, so I have no privelege to embed links.[/size]