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

    I have a model A that implements the "belongs_to" property B.

    I.e.
    A.id
    A.b_id

    B.id
    B.name

    When B exists load() works fine, but if b_id is NULL then load() doesn't tell me.

    I.e.

    A.B.load()->name works and if A.b_id is null then A.B.load()->name produces "Undefined property: AkAssociatedActiveRecord::$name"

    How can I tell if load() actually loaded an object or not?

    Also, calling load() seems quite inefficient. Can I load B automatically when A loads from model As $belongs_to definition? (i.e. eager loading)

    Kind regards,

    John
    •  
      CommentAuthorfrancois
     
    Hi JCC,

    The load method return false when no association object is found. Just check this condition

    if(!$objectAssociatedB = $A->B->load()){ treat error }

    Francois
    • CommentAuthorKaste
     

    Also, calling load() seems quite inefficient. Can I load B automatically when A loads from model As $belongs_to definition?

    yes, you can.

    $A->find('all',array('include'=>'B'));