Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since your predicate or filter object is an array just test the length. If it is zero then don't apply the where clause. You have already defined query so there is no need to do anything else.</p> <pre><code>function getAll(predicate, dataObservable) { var query = breeze.EntityQuery.from('Data'); if (breeze.Predicate.isPredicate(predicate) &amp;&amp; predicate.length !==0) { query = query.where(predicate); } return manager.executeQuery(query).then(success).fail(failure); } </code></pre> <p><strong>EDIT</strong></p> <p>In your question I realize you stated you can refactor your code after I provided this answer. Without going into too much detail, I choose to create re-usable queries that can be dynamically created to reduce how much code must be changed if I change my model. It seems that is what you are trying to do as well. I would recommend building a query that is robust enough to take in predicates, an orderBy, a take, and anything else you <em>may</em> use later, and then handle if the passed in objects or variables are null. I feel this is the best approach for writing reusable code. Example - </p> <pre><code>function getEntities(dataObservable, predicates, orderby, take, local) { var query = breeze.EntityQuery.from('Data'); if (local) { query = query.executeQueryLocally(); } if (orderBy) { query = query.orderBy(orderby); } if (take) { query = query.take(take); } if (breeze.Predicate.isPredicate(predicate) &amp;&amp; predicate.length !==0) { query = query.where(predicate); } return manager.executeQuery(query).then(success).fail(failure); } </code></pre> <p>By doing this each subsequent time you need to filter data you can define methods in your data service or directly from your view model to follow the fetch pattern. Now when you go back and change your model or something you have one query to adjust instead of 20.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload