Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

A minor update to searchable, which allows you to pass FALSE from your '... #36

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
5 participants
Contributor

zeroasterisk commented Mar 5, 2012

...subquery' [_addCondSubquery()] and 'query' [_addCondQuery()] methods and bypass the addition to the search criteria -- this allows you to break out of passing a search condition based on some 'special case' values or processing... cheap and easy

A minor update to searchable, which allows you to pass FALSE from you…
…r 'subquery' [_addCondSubquery()] and 'query' [_addCondQuery()] methods and bypass the addition to the search criteria -- this allows you to break out of passing a search condition based on some 'special case' values or processing... cheap and easy

I don't think it matches cake's coding standards, though.
if ($subquery !== false) {

Owner

zeroasterisk replied Mar 6, 2012

Oh? because you'd rather check for === false and return out of the function?

ähm, not exactly, just the spaces around it (just compare it with your code^^)

Owner

zeroasterisk replied Mar 6, 2012

ah yes -- my mistake -- will correct and resubmit the pull request.

skie replied Mar 11, 2012

By specification each of query and subquery method should return empty array (not boolean value).

Member

skie commented Mar 11, 2012

By specification each of query and subquery method should return empty array (not boolean value).

@skie skie closed this Mar 11, 2012

Contributor

zeroasterisk commented Mar 11, 2012

I understand that, but without this, once the subquery function is called in the model. There is now way to abort the search. A subquery is always performed. I have found that sometimes it is much more optimal to about that subquery based on certain search criteria. You could check for an empty array and abort, I suppose.

Member

skie commented Mar 12, 2012

No search is not aborted in case we should ignore just one of search conditions. That's main idea that user can specify search step by step. In case if there are no search conditions applied user get all data.

Contributor

zeroasterisk commented Mar 12, 2012

Yes -- I understand... but in the method on my model which is called by _addCondSubquery() there are some logical exceptions, based on input data, which might result in want to not filter the result set at all, even though we've passing in a value to that function (ie: that value is depreciated, but still a possible input due to old URL).

There is no way to abort executing a subquery and filtering the results with it... even if we pass in a subquery which doesn't filter the results ( WHERE id > 0 or something ) it's still extra and unnecessary weight on the database server. I'd be nice (and I think, easy) to verify that there is in fact something to use as a subquery to check... so my subquery method on my Model can choose not to filter the result set.

Member

skie commented Mar 12, 2012

In case you want to stop the search process it is possible to throw some LogicException and catch it on controller level.

Contributor

zeroasterisk commented Mar 12, 2012

Yes, but all I want to stop is the subquery part of the search, other parameters may well still be valid and should filter the results.

Like this example, where we are passing one depreciated value to the search parameters, and other valid values:

// controller
$this->passedArgs = array('category' => 'depreciated', 'type' => 'text', 'is_active' => 1);

Obviously, I could filter such a simple example in the controller before passing it to the model, but imagine a situation where we didn't know the category was depreciated in the controller -- only by doing a bit of logic in the model did we know. (furthermore, I try to adhere to skinny-controller philosophy)

If you don't like changing the Model's subquery method to return a type of "mixed" (array or false) then I think checking for an empty result before trigging the subquery is a reasonable compromise.... I can't imagine why you'd want to run a subquery on an empty condition set. If you agree, I'll refactor to check for empy instead of false.

Contributor

real34 commented Mar 13, 2012

+1 for this PR. It is sometimes useful to avoid doing a subquery, and for now it is kind of hacky.

An use case for this is a subquery depending on two fields (date min AND date max). It will be defined on one of both in search filters, and return nothing if the second value is empty.

@skie skie reopened this Mar 13, 2012

Member

ajibarra commented Jul 13, 2012

@zeroasterisk was asked to make a new pull request according to latest changes on master.

@ajibarra ajibarra closed this Jul 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment