Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fActiveRecord->set..

posted by frank 10 years ago

Hello,

I'm having troubles with the set functionality of the fActiveRecord. In our MySQL database is a table which contains a column region1 So I try to set the column:

$member->setRegion1("something");
// exception : The column specified, region_1, does not exist

But it now misses the column region_1 which is ofcourse not available because it's called region1. So how can I set the column region1 without altering the column name to region_1 in the database?

With kind regards,

Frank

The method that will do this for you is fGrammar::addCamelUnderscoreRule(). You could add this method call to the configure() method for your fActiveRecord class.

protected function configure()
{
    fGrammar::addCamelUnderscoreRule('Region1', 'region1');
}

This will have the side effect of causing any instance of Region1 becoming region1 in any code that uses fGrammar::underscorize(). I'm guessing that won't really be an issue though.

posted by wbond 10 years ago

Thanx, that solved the problem, but is it now a problem if another table uses the same field names? So for this database table it should become region1 instead of region_1 also.. right? Sorry if this is a beginners mistake, but it just won't seems to work.

Uncaught Exception
------------------
..\\register.php(68): Dat_geo_nl->GetRegion_1()
[internal function]: fActiveRecord->__call('GetRegion_1', Array)
..\\inc\\flourish\\fActiveRecord.php(239): fORM::getActiveRecordMethod(Object(Dat_geo_nl),'GetRegion_1')
..\\inc\\flourish\\fORM.php(346): fORM::parseMethod('GetRegion_1')
Invalid method, GetRegion_1(), called

with kind regards,

Frank

posted by frank 10 years ago

The issue here is that you have capitalized Get. Try calling getRegion1() instead.

With the fGrammar change, getRegion1() will look for a column named region1 for any table. If you have a table with region_1 you might need to type getRegion_1(), however I don't know for sure if that will work.

posted by wbond 10 years ago

Thanx this is correct,

After hours behind the computer screen i overlooked this typo. By the way this library is awesome, i'm using it for a dating site, when it's finished i will sent you the link!!

By the way is there a way to use regualar expressions in the fValidation class?

Frank

posted by frank 10 years ago

This solution should be included somewhere in the documentation around http://flourishlib.com/docs/fORM#ColumnandRecordNames. I was going nutz trying to figure this out and had to click on each thread hoping to find a solution.

posted by gabrielu 9 years ago

Thanks for the note. I've added links to the fORM, OrmConventions and fActiveRecord pages about this.

posted by wbond 9 years ago