Does CakePHP finderQuery work with SQL Server? Where would I debug this?

I'm new to cakePHP, so I may miss the obvious.

The system is performing the last boot using Microsoft SQL Server 2005 as the database. I understand that this is a bit unusual, but after fixing the URL rewrite, I did not see other problems.

I would like to use custom finderQuery, but I can't even replace the default value. In particular, if I use

var $hasMany = array( 'RecyclateTypeConversion' => array( 'className' => 'RecyclateTypeConversion', 'foreignKey' => 'recyclate_type_id', 'dependent' => false, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderQuery' => 'select RecyclateTypeConversion.* from recyclate_type_conversions AS RecyclateTypeConversion WHERE RecyclateTypeConversion.recyclate_type_id IN ({$__cakeID__$});', 'counterQuery' => '' ), }; 

I see this error

Note (8): Undefined index: RecyclateTypeConversion [CORE \ pie \ LIES \ model \ Data sources \ dbo_source.php, line 1099]

However, the output from SQL debugging confirms that the query itself works fine and returns 4 records, and the view works fine when finderQuery is not specified. I tried for other hasMany tables too - with the same problem.

I tried to replace the selection with certain fields, but I still see the same result. Of course, the query looks right according to the manual - so what is the problem (and could this be related to using MSSQL?)

EDIT: Also, since it has not yet been able to find answers to the questions, which approach is best to debug? I started the hunt through the cake debugging class, but so far without the results that enlightened me. Of course, if a problem occurs, I will send the patch back to the project.

+6
source share
4 answers

Have you verified that there is actually a model called RecyclateTypeConversion and that it exists with a file name in accordance with CakePHP conventions? That is, is there models/recyclate_type_conversion.php in this file as well - the name of the model defined as RecyclateTypeConversion .

The error you get suggests that something is wrong with this model name because it cannot find the associated index.

+2
source

Try removing the alias from select - queuing in AS "RecyclateTypeConversion" should handle this for you. I would also like to add custom queries in double quotes. I could just be paranoid, but parsing errors hit me in the ass earlier.

 var $hasMany = array( 'RecyclateTypeConversion' => array( 'className' => 'RecyclateTypeConversion', 'foreignKey' => 'recyclate_type_id', 'dependent' => false, 'finderQuery' => "select * from recyclate_type_conversions AS RecyclateTypeConversion WHERE RecyclateTypeConversion.recyclate_type_id IN ({$__cakeID__$});", ); 

In addition, I highly recommend that you use the DebugKit plugin and send us a query log and debug output of search results that cause errors.

+2
source

Did you go through it step by step?

  • try to get all (all data)
  • try the conditions
  • try โ€œpent-upโ€ behavior to create your request, which makes thinking a lot easier, in my opinion.
+1
source

Have you tried the CugPHP Debug Kit

0
source

Source: https://habr.com/ru/post/889029/


All Articles