Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Undefined index: id
san8616
July 2020
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
Harro
July 2020
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?
san8616
July 2020
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'
)
Harro
July 2020
I assume your "order class" is \\Invoice\\Model_Order?
In both models, the 'id' column is defined in $_properties?
san8616
July 2020
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
Harro
July 2020
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?
soseki
July 2020
I guess you should define as Model_Product in the has many relation, not as Model_ProductModel.
san8616
July 2020
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.
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
July 2020
san8616
July 2020
soseki
July 2020