Further to my post regarding a where clause, I am now trying to do the same using a join.
I have a table named Client that can have many corresponding records in Invoice. I am trying to apply this relationship in the Client::search() method with the following code:
$criteria=new CDbCriteria;
$criteria->join='LEFT JOIN Client ON Client.id=Invoice.clientId';
$criteria->condition='Client.businessId='. Yii::app()->userInfo->business;
However, this is returning the error: Column not found: 1054 Unknown column ‘Invoice.clientId’ in ‘on clause’
But this column does exist and I get the result I expect if I manually write the following into MySQL directly:
SELECT Invoice.id,clientId,Invoice.active,Client.id AS client_id,Client.businessId FROM Invoice
LEFT JOIN Client ON Client.id=Invoice.clientId
WHERE Client.businessId=1;
It seems that even though the code is running within the Invoice model, the table Invoice is unknown. Do I need to specify the table some other way?
Pleae help me i want to make this type of query "SELECT * FROM table1 a, table2 m WHERE a.colid=1 and m.colid=1 order by a.date desc" in Join using CDbCriteria in search function in model
ya everything is working in normal way with relationship but i need to combine two tables data fetching data on criteria of table 1 view in widget in view of admin
If you ever want that kind of "service", you have to be willing to pay for it.
IMHO, this forum is under the spirit of open source software. You may get what you want for free, if you are willing to share your knowledge and experience. You have to be honest and frank, sometimes exposing your stupid broken codes. If you are too proud to do that, you may want to hire some private teacher.