views:

187

answers:

3

Hi, I was using KohanaPHP ORM but I can't use it with my database table structure. So, I need a framework or library ORM to use with it.

With Kohana I need to follow a naming convention. I can't use a field name (foreign key) like 'idUnidadeMedida'.

Are there any suggestions?

Thank you.

+1  A: 

Doctrine is PHP's most powerful ORM (and database abstraction layer) - there's not much it can't do. V2 (soon to be released) may well become the de-facto standard, and will see integration with frameworks (i.e. Zend, although it's easily used stand-alone too).

Andy
Can I define my database tables structures? Thank you guy!
Thomas
Andy
+2  A: 

Actually, Kohana ORM isn't that limited. In case of Ko3's ORM, you can define everything concerning your relationships as I explained here;

http://stackoverflow.com/questions/2158745/how-do-i-relate-tables-with-different-foreign-key-names-in-kohana-orm/2689698#2689698

( look at the code, not explanation, since that guy asked for varchar FKs )

Kemo
I did it:protected $_has_one = array('unidade' => array('model' => 'unidade', 'foreign_key' => 'pro_idUnidadeUso'));but i got:Database_Exception [ 1054 ]: Unknown column 'unidades.pro_idUnidadeUso' in 'where clause' [ SELECT `unidades`.* FROM `unidades` WHERE `unidades`.`pro_idUnidadeUso` = '2' ORDER BY `unidades`.`uni_codigo` ASC LIMIT 1 ]:(
Thomas
@Thomas: your foreign key's name really is 'pro_idUnidadeUso'? Maybe 'idUnidadeUso' only ? That's a MySQL error, not model error :) You haven't passed the right FK name.
Kemo
So, let me explain it better.I have 2 tables: produtos and unidades. A produto has an unidade and produto table has a field named pro_idUnidadeUso that references to an unidade id. Got it?Thank you.
Thomas
@Thomas you've defined the pro_idUnidadeUso in the wrong model ( unidades instead of produto ). That's a database error you're getting, still not model. You don't have a pro_idUnidadeUso field in unidades table.
Kemo
+1  A: 
<?php
class Model_Produto extends ORM {
    protected $_table_name = 'produtos';
    protected $_primary_key = 'pro_codigo';
    protected $_has_one = array('unidade' => array('model' => 'unidade', 'foreign_key' => 'uni_codigo'));
}
?>

<?php
class Model_Unidade extends ORM {
    protected $_table_name = 'unidades';
    protected $_primary_key = 'uni_codigo';
}
?>
Thomas
Please don't answer to your own question if it's not the actual answer. Look at my last comment, basically you've been mistaking belongs_to and has_one foreign keys by putting them into wrong models. Have fun using kohana :)
Kemo