sorry for bothering you again with this post, but I’m still struggeling with the getter.
Any hint is highly appreciated. (Also, if you would suggest a completely different approach)
Thank you very much in advance.
cheers
Steffen
Background info on the concept:
Besides Share there’re/will be hopefully many other investment types/data structures which I try to address in a unified way: <type> -> <field name> e.g. Share->name. So, I cannot hard code in the investment view investment->share->sharesub->name as I would do it with standard related ARs.
Hmm, frankly speaking i don’t really understand the relation model. But from your relations, why can’t you do:
$data->share->sharesub->name;
Maybe this helps: Try to find out, which SQL you need to get the data for the datagrid. The SQL should create a compact result set where each row corresponds to a single row in the datagrid. If you can find this SQL, show it here, then we can maybe translate it back to AR.
yep, this was also my first approach until I recognized that the way how I access the var must be more generic.
central problem: there are different data structures for various types of shares, public pension, statutory pensions, …
I tried to explain it above:
put it the other way round, in a central investment overview using the suggested rAR I could not generate mixed type list. So, I would have to list one with a certain -> -> structure, then type 2 with its own -> -> rAR structure and so on.
Now, I wanted t get rid of this restriction by accessing any major attribute e.g. name of an investment by <function that gets the investmentID and returns the appropriate model> -> name (like share->name or pension->name). This way I could structure the data according to the specific needs of the investment type without having to think about its accessability.
Hope, I could somehow explain, what I’m trying to achieve.
I guess i don’t get it. You want mixed types of data (or related data) somehow displayed in a single table? How should that be displayed? Not to mention how to handle e.g. sorting, paging, filtering…
Like i said: If you want to do this, you’ll end up with (at least) one other subquery per rendered row in your grid, since the related types are not homogeneous and can’t be fetched with a single query. This will at least make problems with e.g. sorting by type.
Sorry that i can’t help you much further on this. Maybe someone else has an idea. My guess is, you’ll have to reconsider your DB layout, but i might be wrong since i had no time to think it through completely (which is your job after all ).
public function getName($_typeID)
{
$hInvestmentType=array('ID1'=>array('lcase'=>"share", 'ucase'=>"Share")); // will be moved to separate function and filled from db
$this->_field=$hInvestmentType["ID".$_typeID]['ucase']::model()->name;
return $this->_field;
}
models/Share.php
public function getName()
{
$this->_name="\$data->share->sharesub->name";
return $this->_name;
}
principle of operation:
View calls function in investment model and passes the typeID. There the request is routed to the appropriate model according to the investment type. Within the type-specific model the string is replaced by the actual location of the data. Back to the view the final rAR string is eval’d.
Performance is probably not ready for a real productive application (but for me it’s enough)
Thanks to everyone having thought about this issue.
Congrats… that solution is close to that provided in Yii cookbook creating blog (page 30 Lookup model) - maybe having a look at it could improve the performance