pungpoo / giix

Automatically exported from code.google.com/p/giix
0 stars 0 forks source link

Criteria of the search() method should use the table alias. #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When using the relationships in the model, in some cases error occurs in the 
query as below:

When using the relations in the model error often occurs in the query to the 
database due to ambiguity, as follows:

Error 500: CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity 
constraint violation: 1052 Column 'id_action' in where 
clause is ambiguous.

To avoid this, simply add the table alias in the creation of the criteria.

Because this method is placed in the base file, it would be necessary to change 
the pattern of model generation.

Original issue reported on code.google.com by thiagota...@gmail.com on 26 May 2011 at 10:01

GoogleCodeExporter commented 8 years ago
Could you please paste here the line and the line of the error and the 
generated query? Thank you.

Original comment by rodrigo.coelho@gmail.com on 27 May 2011 at 12:46

GoogleCodeExporter commented 8 years ago
I mean the **file** and the line of the error.

Original comment by rodrigo.coelho@gmail.com on 27 May 2011 at 12:47

GoogleCodeExporter commented 8 years ago
Rodrigo is not a "mistake" of the giix.

The problem I mentioned is the necessity of having to change the base file, 
which should remain untouched.

This could be solved if the giix generate the search criteria with the alias of 
the tables.

Original comment by thiagota...@gmail.com on 27 May 2011 at 1:21

GoogleCodeExporter commented 8 years ago
Yes, if I can make giix better by generating the search criteria with the alias 
of the tables, I'll be happy.

But for that I'll need to understand what is happening. If you can send me more 
information, like the requested above, that will help. Thank you!

Original comment by rodrigo.coelho@gmail.com on 27 May 2011 at 1:26

GoogleCodeExporter commented 8 years ago
A brief example of the situation.

Table Company
-----------
id_company (pk)
nm_company

Table Employee
----------
id_employee (pk)
id_company (fk)
nm_employee

Controller: employee/list
--------------
CGridView
'dataProvider'=>Employee::model()->with('company')->search();

In the search form, if I search by company id, I get the error shown above.

This is because the query will be the two tables, employee and company, and the 
search criteria will be only 'id_company' = :yp0.
As this field exists in both tables, the database complains ambiguity.

since in the consultation will be two tables, employee and company, and the 
search criteria will be x.

Original comment by thiagota...@gmail.com on 27 May 2011 at 1:59

GoogleCodeExporter commented 8 years ago
Thank you for the information.

Original comment by rodrigo.coelho@gmail.com on 27 May 2011 at 9:11

GoogleCodeExporter commented 8 years ago

Original comment by rodrigo.coelho@gmail.com on 27 May 2011 at 9:22

GoogleCodeExporter commented 8 years ago
Thank you for your attention.

Did you see the other questions that I opened?
I opened another question also about the search() that is given priority over 
that. Without the modification of the first, this problem does not happen, 
since no one has the possibility to use scopes or criteria in the model. That 
sucks because it forces us to work with lazy load.

Original comment by thiagota...@gmail.com on 27 May 2011 at 11:03

GoogleCodeExporter commented 8 years ago
Ok, thanks for the information.

Original comment by rodrigo.coelho@gmail.com on 27 May 2011 at 12:46