Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Undefined index: id
  • hi,

    I have Order class with has_many relations to product class
        protected static $_has_many = array(
            'products' => array(
                'key_from' => 'id',
                'model_to' => '\\Invoice\\Model_Product',
                'key_to' => 'order_id',
                'cascade_delete' => true,
                'cascade_save' => true

    If I set "cascade_save' = true, I get error Undefined index: id while saving order.

    If I set 'cascade_save'= false, I do get all product details but do not get product id's. by using has_many relation.

    NOTE THAT I have updated fuelphp from 1.3 to 1.8

  • How is the related defined on the other side, in Model_Product?

    Also, do both models have an "id" column, and is that column defined as auto_increment?

  • hi,

    Yes. Both models have "id" column and are defined as auto_increment.

    Here is related for from Model_Product,

    protected static $_belongs_to = array(
            'event' => array(
                'key_from' => 'event_id'
                'model_to' => '\\Event\\Model_Event'
                'key_to' => 'id',
                'cascade_save' => false
            'product_model' => array(
                'key_from' => 'product_model_id'
                'model_to' => '\\Invoice\\Model_ProductModel'
                'key_to' => 'id',
                'cascade_save' => false
            'coupon' => array(
                'key_from' => 'coupon_id'
                'model_to' => '\\Invoice\\Model_Coupon'
                'key_to' => 'id',
                'cascade_save' => false
            'order' => array(
                'key_from'  => 'order_id',
                'model_to' => '\\Invoice\\Model_Order',
                'key_to' => 'id'
            'customer' => array(
                'key_from' => 'customer_id',
                'model_to' => '\\Invoice\\Model_Customer',
                'key_to' => 'id'
  • I assume your "order class" is \\Invoice\\Model_Order?

    In both models, the 'id' column is defined in $_properties?
  • Hi, Yes, order class is \\Invoice\\Model_Order
    And yes 'id' column is defined in $_properties.

    Just for information, code was perfectly working before upgrading to 1.8.2

  • I don't really see any issue with the relation defintiion.

    Is the problem specific to this relation? Or does it also happen with other relations?

    Do you have details about the erorr? Can you post the info from the error, such as class and line, and the backtrace?
  • I guess you should define as Model_Product in the has many relation, not as Model_ProductModel.
  • Hi, 
    I will check with it. 
    We are calling functions from ajax call so not getting enough backtrace. I will put any info I find.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion