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


    it may seem strange, but I can't get akelos to set an integer attribute in my tables to the value 0.

    I have a products table and model with a 'products_status' field. However,

    $product->updateAttribute( 'products_status', n);

    works for n != 0 only!

    Any idea why?


    • CommentAuthorKaste

    hm, updateAttribute() just calls setAttribute($attribute_name,$value) then saves.

    actually, in the end it does a simple $this->$attribute_name = $value;

    so, could you double-check spelling. do you have a explicit setter (like setProductsStatus)?

    • CommentAuthortom
    ok, I double-checked everything today. It really depends on the value I'm trying to set. Values 1 or 2 work as expected, but 0 doesn't.

    Might it be that there's a check via empty() somewhere which concludes that an integer 0 is empty and does not need to be saved?
    • CommentAuthorKaste

    might share your unit test?

    one thing, what's the result of

    ->hasAttribute('my_attribute_name');  // = true?


    • CommentAuthortom

    Ok, heres the test case code:

    function test_Product()
        $prod = new Product( array( 'products_status' => 2 ));
        print_r( $prod->getAttributes()  );
        $this->assertTrue( $prod->hasAttribute('products_status'),'Attribute doesnt exist.');
        $this->assertTrue( $prod->save(),'Saving the product failed. :(');
        $prod = $prod->find('first');
        $prod->updateAttribute( 'products_status', 0 );
        $prod = $prod->find('first');
        $this->assertTrue( $prod->products_status == 0,'Setting to 0 failed. products_status is '.$prod->products_status);

    The last assertion fails, saying:

    1) Setting to 0 failed. products_status is 2

    print_r output includes

    [products_status] => 2
    • CommentAuthorKaste

    works for me. just assumed

    Product: id, products_status int

    and a clean Model-Class

    • CommentAuthorasejua

    I've placed a new post about this topic (sorry for that, founded this one later)

    I'm having the same problem Tom has and I've traced the place where the "problem" happens.

    Can you explain your last message (the Product: ... and a clean Model-Class thing), I'm still feel newb with Akelos :)

    Thanks and sorry for the doubled post :$

    • CommentAuthorKaste

    Can you explain your last message (the Product: ... and a clean Model-Class thing)

    table products has two columns: id & products_status. Both int's.

    the model is 'clean', without associations, validations etc.

    • CommentAuthorKaste

    ok, with

     products_status int not null

    I can reproduce this.

    • CommentAuthorKaste

    thank you for finding this. please create a ticket.

    • CommentAuthorasejua

    Thanks Kaste for fixing it and for your patience :)

    • CommentAuthortom
    Ok, made a ticket.

    Sorry it took so long, and thanks for helping! :)

    • CommentAuthorsuthern

    I realize this is an old thread, but I'm still having trouble updating a field to the value of '0'. It just does not save it. I guess I can add my own save callback (one of the onSave or onValidate ones) code that actually performs it's own SQL update query for the field changing to 0, but that's kinda silly.

    • CommentAuthorsuthern

    ok, I take that back. The value of 0 or NULL does get sent to the database. It's working!!