Welcome Guest, Not a member yet? Register   Sign In
Datamapper get_rules on related tables
#2

[eluser]Dunmail[/eluser]
Found a solution. It may not be the ideal or recommended way though.

I extended the DataMapper class and put the formatting functions in the new class then had my DataMapper models extend the new class.

Code:
class DataMapperExt extends DataMapper {
    function _format_name($field){
        ...
    }
}

Then the club class does this
Code:
class Club extends DataMapperExt{
    var $validation = array(
            'club_name' => array(
                'label' => 'Given Name',
                'rules' => array('trim'),
                'get_rules' => array('format_name')
            ),
            'member_given_name' => array(
                'label' => 'Given Name',
                'rules' => array('trim'),
                'get_rules' => array('format_name')
            )
    );
}

Doing it this way lets all my models have access to the formatting functions, I just have to remember to name the fields correctly when accessed via a relation - see the second rule.


Messages In This Thread
Datamapper get_rules on related tables - by El Forum - 02-21-2013, 05:53 AM
Datamapper get_rules on related tables - by El Forum - 02-22-2013, 01:39 AM
Datamapper get_rules on related tables - by El Forum - 02-22-2013, 09:27 AM
Datamapper get_rules on related tables - by El Forum - 02-27-2013, 01:40 PM
Datamapper get_rules on related tables - by El Forum - 02-28-2013, 12:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB