activerecord add custom sql to query

Discuss about Group-Office development here

Moderator: Developers

glemigh
Posts: 28
Joined: Wed Aug 24, 2005 10:22 pm
Location: Venice, FL

activerecord add custom sql to query

Postby glemigh » Tue Jun 03, 2014 9:48 pm

I have grid filters, and I need to insert the WHERE clause into the query before the query gets executed.

I think I can figure out how to get my params, but what function can I use to "stuff" my WHERE clause into the query?

I believe I need to accomplish this within the Controller I have abstracted from AbstractModelController?

Thank you,

George
richarddodd
Posts: 66
Joined: Fri Jun 21, 2013 2:55 pm

Re: activerecord add custom sql to query

Postby richarddodd » Thu Jun 05, 2014 12:27 pm

You can add custom criteria to your query (FindParams instance) by doing something like

Code: Select all


$fparams 
= GO_Base_Db_FindParams::newInstance();
$fparams->getCriteria()
  ->addCondition(<your condition here>);
$stmt GO_Module_Model_YourModelName::model()->find($fparams);
 

I have used this for quite exotic things like "AND NOT EXISTS" subqueries. Check out the source code for GO_Base_Db_FindCriteria::addCondition() to see how it works.
glemigh
Posts: 28
Joined: Wed Aug 24, 2005 10:22 pm
Location: Venice, FL

Re: activerecord add custom sql to query

Postby glemigh » Sat Jun 07, 2014 9:01 pm

Thank you very much, that was just the hint I needed to figure it out.

George

Return to “Development Chats”

Who is online

Users browsing this forum: No registered users and 1 guest

cron