Note that there are some explanatory texts on larger screens.

plurals
  1. POArray displays length of 0 sometimes
    primarykey
    data
    text
    <p>I am having an extremely bizarre problem. I have a Backbone collection, and I am using the where method to find models in the collection that match a certain attribute. My problem is the inconsistency of the results.</p> <p>I have a joinedGoalList which keeps track of goals that a user has joined. Let's say that this collection contains two goals with IDs of 1 and 3. When a user accesses /goals/3, a message should display saying that the user has joined the goal</p> <p>I am having a problem where I am accessing /goals/3, and half the time the message displays, and the other half of the time, the message does not display.</p> <p>The odd thing is that this problem only happens on my remote server and not on my local host.</p> <p>In my code, I query the joinedGoalList for an ID of 3, and if it matches, I know that the matches array has to be greater than 0, so I render the message showing that the user has joined the goal.</p> <p>Here is the code (joinedGoalList is a Backbone collection:</p> <pre><code> console.log(joinedGoalList); var matches = joinedGoalList.where({id: this.model.get("id")}); console.log(matches); console.log(matches.length); if (matches.length &gt; 0) { console.log("the matches length is &gt; 0"); this.renderLeaveGoal(); } else { console.log("the matches length is 0"); this.renderJoinGoal(); } </code></pre> <p>Here are the results of <code>console.log(joinedGoalList)</code>, here are the results(they are consistent):</p> <pre><code>child _byCid: Object _byId: Object _callbacks: Object length: 2 models: Array[2] __proto__: ctor </code></pre> <p>As you can see, the length is 2. One of the objects has an ID of 1 and the other object has an ID of 3. This is consistent throughout the page loads.</p> <p>The inconsistency occurs when I do a match on the array for an object with an ID of 3. Some page loads find the match while other page loads do not find the match.</p> <p>The results of <code>console.log(matches.length)</code> are either 0 or 1 on my remote server, yet on my localhost, the results are always 1.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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