I have a strange scenario due to the way the old software was set up
due to customers wanting their job numbers starting from a certain number i.e 500
When saving a new job i have to look into another table for the associated job number for that customer
and place it in the record
then increment the number (that i have just used ) by 1 in the ‘jobno’ table ready for use the next time
i have all the relationships set up and i thought that i could simply use
$model->job_no = $model->customer->jobNos->Jobno; for the first part
where customer and jobNos are relationship names but this gives me an error "Trying to get property of non-object"
However it can be simply displayed that way in a view
Any ideas as to how i could accomplish both parts of this problem ?
What are your relation exactly in your model, and in table link to costumer relation.
"Trying to get property of non-object" means $model->job_no or $model->customer or $model->customer->jobNos are not existing object property.
Thanks for the reply , i have job model with the following relations
'customer' => array(self::BELONGS_TO, 'Customers', 'customer_ID'),
and in the customer model the relationships are
'jobs' => array(self::HAS_MANY, 'Jobs', 'customer_ID'),
'jobNos' => array(self::HAS_ONE, 'JobNo', 'Customer_ID'),
'warranties' => array(self::HAS_MANY, 'Warranty', 'customer_ID'),
'contacts' => array(self::HAS_MANY, 'Contacts', 'customer_ID'),
Note that the relationship for ‘jobNos’ i changed to HAS_ONE from HAS_MANY as this made more sense
the funny thing is that in a view related to the jobcontroller i can do this
<?php echo CHtml::encode($model->customer->jobNos->JobNo ); ?>
and it will display the correct number
I guess the real question here is should i be able to do this ?
Because i’m struggling to get it