fActiveRecord->set.. / Help Please!

fActiveRecord->set..

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

  • Message #411

    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.

    • Message #647

      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.

    • Message #415

      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

      • Message #416

        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.

        • Message #417

          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

  • Message #680

    To all drivers! Hello! Come on <a href=http://vancuver.in>Auto portal today</a>.