6 Commits

Author SHA1 Message Date
Douglas Danger Manley
2879c7e762 Issue #3007: Fix search clone array corruption
Method-chaining in gorm is predicated on `search`'s `clone` method
returning a copy of the `search` instance such that no change that
is made to the copy affects the original.

However, the original implementation copied the slices of the various
slice properties (such as `whereConditions`), with the incorrect
understanding that `append` would create a new slice each time that
it was called.  In some cases, this is true.  Practically, go
doubles the size of the slice once it gets full, so the following
slice `append` calls would result in a new slice:

* 0 -> 1
* 1 -> 2
* 2 -> 4
* 4 -> 8
* and so on.

So, when the number of "where" conditions (or any other slice
property) was 0, 1, 2, or 4, method-chaining would work as expected.
However, when it was 3, 5, 6, or 7, modifying the copy would modify
the original.

The solution is simply to create new slices in `clone`.
2020-05-07 16:54:33 -04:00
Jinzhu
da7830ea50 Add SelectAttrs, OmitAttrs 2015-03-12 15:50:38 +08:00
Jinzhu
6e5d46bf37 Refactor Search API 2015-03-12 14:47:07 +08:00
jnfeinstein
429a100856 Add additional methods of specifying the 'select' portion of a query.
This commit adds more ways of specifying selects:

-) You can now pass in a []string.  This is mostly for convenience,
since you may want to dynamically create a list of fields to be
selected.

-) You can now use variables.  This is important because a select
could take user input.  For example, finding a MAX between a record
and a given number could be easily done using select, and then
you don't have to process anything in backend logic.  This is also
necessary to use postgres text search capabilities (which actaully
play nicely with the rest of gorm).

-) You can now chain select calls.  This could be useful in
conjunction with gorm's scopes functionality.
2014-11-17 07:36:26 -05:00
Jinzhu
6f1dd5fae3 API for search 2014-01-28 16:56:51 +08:00
Jinzhu
7912631be7 Make clone search conditions works 2013-11-16 09:12:22 +08:00