Hello, in my application I have a hierarchy of company, organisational unit and sub-unit. Some data should be configurable on every level but not compulsory on every level. If it is not defined for the sub-unit it should be taken from the unit and if it is not there from the company.
An example for such data are text snipplets, saved in a table 'textbausteine' with a corresponding class. Now I want a mechanism where I can just ask for a certain text- snipplet for the sub-unit without bothering from what level of the hierarchy the actual data is taken. I have written such a method but it looks very clumsy and I think there must be a more elegant way to do this. This is the code for just one level up the hierarchy sub get_text { my $class = shift; my %params = @_; my $praxis_id = $params{praxis_id} or return; if ( my ($t) = @{$class->get_textbausteine(query => [%params])}) { return $t->text; } else { # get default from organisation # that is: organisation of praxis with a praxis_id of 0 delete $params{praxis_id}; my $o = PVonline::Praxen->new(nr => $praxis_id) ->organisation_id; my ($t) = @{$class->get_textbausteine( query => [ %params, praxis_id => 0, organisation_id => $o, ])}; $t ? return $t->text : return; } } There would be an additional level with praxis_id = 0 and organisation_id = 0 for the company wide defaults. Ideally I would like some sort of generic method with the possibility to pass a code ref that implements the algorithm to walk up one level in the default- hierarchy. Is there a shortcut to do something like this? Perhaps it would be enough to have some kind of short circuit OR for records: $obj = $class->get_x(query1) || $class->get_x(query2) || ... And a related question: Is there a manager method for cases where I know there can be only one (or zero) hits but the query params don't build the primary keyor a unique column (only the combination is unique)? See the if-condition in my example. I know there is only one snipplet with name 'bill-text' for any given (sub-)unit but still have to do all this dereferencing und moving from array to scalar. So somehow I think what I want to do should be quite common and if I still feel so uncomfortable writing the code my suspicion is that I am doing something wrong. Any better ideas? Thanks, Michael ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object