Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthortom
     
    Hi,

    has eager loading of belongs_to associations been implemented yet? Somehow, I'm having trouble getting it to work...

    Regards,
    T.
    •  
      CommentAuthorbermi
     

    It's implemented. Can you post a code example/unit test?

    • CommentAuthortom
     

    Hi,

    actually, in my case, it is a has_one relation. here's some code:

    In my app, I've got a model for Products in an online store, and each of them has_one ProductDescription. This is declared in my Product class, like this:

    var $has_one = array(
        'description' => array( 'class_name' => 'ProductDescription', 'foreign_key' => 'products_id' ));
    

    In ProductDecription, it's a belongs_to:

    var $belongs_to = array( 'product' => array('primary_key' => 'products_id' ));
    

    So I should be able to do

    $p = $this->Product->find( 1234, array('include'=>'description));
    

    and then access the product's description via

    $p->description->products_name;
    

    right?

    However, I get:

    Unexpected PHP error [Undefined property:  AkAssociatedActiveRecord::$products_name]
    

    Might it be that custom key names and/or custom table names interfer with the 'include' feature? I've got a nonstandard table name for the table holding the products_descriptions, which Im setting in the constructor of ProductDescription.

    Regards,

    Tom

    Just ask if you need more info....

    •  
      CommentAuthorbermi
     

    Tom,

    Add before

    $p = $this->Product->find( 1234, array('include'=>'description));
    

    this

    $this->Product->dbug();
    

    and you'll be able to debug the SQL answering some questions like: Does the SQL includes the JOIN statement? Does it returns expected results when running it on phpMyAdmin?

    BTW, why not simply add the "description" column to the products table?