Source: plugins/search.js

  1. Rekord.on( Rekord.Events.Plugins, function(model, db, options)
  2. {
  3. /**
  4. * Creates a new search for model instances. A search is an object with
  5. * properties that are passed to a configurable {@link Rekord.rest} function
  6. * which expect an array of models to be returned from the remote call that
  7. * match the search parameters.
  8. *
  9. * ```javascript
  10. * var Task = Rekord({
  11. * fields: ['name', 'done']
  12. * });
  13. * var search = Task.search('/api/task/search');
  14. * search.name = 'like this';
  15. * search.done = true;
  16. * search.anyProperty = [1, 3, 4];
  17. * var promise = search.$run();
  18. * promise.success( function(search) {
  19. * search.$results; // collection of returned results
  20. * });
  21. * ```
  22. *
  23. * @method search
  24. * @memberof Rekord.Model
  25. * @param {String} url -
  26. * A URL to send the search data to.
  27. * @param {searchOptions} [options] -
  28. * Options for the search.
  29. * @param {Object} [props] -
  30. * Initial set of properties on the search.
  31. * @param {Boolean} [run=false] -
  32. * Whether or not to run the search immediately.
  33. * @return {Rekord.Search} -
  34. * A new search for models.
  35. */
  36. model.search = function(url, options, props, run)
  37. {
  38. return new Search( db, url, options, props, run );
  39. };
  40. });