In the feature/v2 branch, the has_fields method et al. looks like:
def has_fields(self, *fields):
self.terms.append(['$has_fields', fields])
return self._clone()
def _clone(self):
query = type(self)(self.schema)
query.terms.extend(copy.deepcopy(self.terms))
return query
has_fields() Reference
_clone() Reference
I'm assuming self isn't being returned directly because Query objects are intended to be immutable.
getAllQuery = montage.Query('movies');
hasFieldsQuery = getAllQuery.hasFields('field');
limitQuery = getAllQuery.limit(1);
Unless I'm missing something, getAllQuery, hasFieldsQuery, and limitQuery would have different references but their terms would overlap because terms.append() happens before the copy.deepcopy().
More specifically, getAllQuery would get the terms from the .hasFields() call and hasFieldsQuery and limitQuery would have identical terms.
- Are my observations above correct?
- Should Query instances be immutable? (so I can duplicate this behavior in the
javascript-montage wrapper).
In the
feature/v2branch, thehas_fieldsmethod et al. looks like:has_fields() Reference
_clone() Reference
I'm assuming
selfisn't being returned directly because Query objects are intended to be immutable.Unless I'm missing something,
getAllQuery,hasFieldsQuery, andlimitQuerywould have different references but their terms would overlap becauseterms.append()happens before thecopy.deepcopy().More specifically,
getAllQuerywould get the terms from the.hasFields()call andhasFieldsQueryandlimitQuerywould have identical terms.javascript-montagewrapper).