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

    object->save() used to return the object saved if the save was good, and false if the save failed.

    Now it returns 'true' instead of the object. How can I get the id of the recently saved (created) object?

    (I'm creating an 'order' and 'order_items' all in one function.)
    Thanks!

    • CommentAuthorKaste
     

    hm...

    $object->save();
    $object->getId();
    

    object->save() used to return the object saved if the save was good, and false if the save failed.

    svn blames me for that line. should it return the object? use-case?

    • CommentAuthorsuthern
     

    Here's my use. I have a sales order creation page. On this page are 'orders' fields of Vendor ship to address, memo, expected delivery date, and other stuff that applies to one 'orders' record.

    ALSO on the same page I have multiple lines of 'orders_parts' which are line-items. Each of the orders_parts has things like part_id , description, qty, rate..etc.

    In my order_controller I have an 'create' function which shows the form in the first paragraph, and when the form is submitted it first saves the 'order', then it does a loop and saves all the 'orders_parts' with an order_id set to the id from the object from order->save().

    Does that make sense?

    • CommentAuthorsuthern
     

    object->getId() works great, so I guess save() dosen't really need to return the object, unless someone else can think of a reason.

    Thanks for the quick response Kaste!

    • CommentAuthorKaste
     

    but when you

    $order->save()
    

    you already have the $order-instance.

    at the end of save() we could return $this. so you could chain some method calls. but since a save can always fail (and the return false), this would be unpredictable unless we throw exceptions.

    in short

    $order === $order->save()
    
    • CommentAuthorsuthern
     

    Auto-incrementing fields (like 'id') are the only thing that i can think of that is added because of a ->save(). What about other non-id, autoincrementing fields? Are they pushed into the object when the $object->save() occurs? Just curious.

    •  
      CommentAuthorbermi
     

    Suthern, at least in MySQL I think its not possible to have multiple autoincrement fields.

    If a field is set automatically by the database (ie. using functions as defaults), you'll need to call $order->reload(), to get the changes the Active Record was not aware of.

    • CommentAuthorsuthern
     

    That makes sense. Thanks Bermi!