Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthortom
    • CommentTimeMar 18th 2008
     
    Hi,

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

    Regards,
    T.
    •  
      CommentAuthorbermi
    • CommentTimeMar 18th 2008
     

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

    • CommentAuthortom
    • CommentTimeMar 19th 2008
     

    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
    • CommentTimeMar 19th 2008
     

    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?

Add your comments
    Username Password
  • Format comments as