<p>Hey Sam the answer is in your own dump file. Just look at the userModel Numbers in userFollowing, userFollowers and friends.</p>

<p>UserFollowing has [379, 381, 393], 
UserFollowers has [446, 454] and 
friends has [379, 381]</p>

<p>Friends has the same numbers as userFollowing but not the same as userFollowers. Hence when you do the without filter on userFollowers you are basically doing
[446, 454]|without([379, 381])
Which will ofcourse return [446, 454]. </p>

<p>You could ofcourse get the username out for each model and perform the operations on that and since those would be strings this would work.</p>

CC BY-SA 3.0
2015-02-17T07:23:35.683Z
Ah, exactly what I've been trying to get my head around. So do model numbers not relate to the user object?
Sam Hibberd
CC BY-SA 3.0
2015-02-17T08:59:04.443Z
You are correct. There is no connection between model number and user model. The same user can have different model numbers at different times because each time a new model will be created for that user.

You can even try this to see the model number change on each refresh:
{{ dump(craft.users.first()) }}
Moin Qidwai
CC BY-SA 3.0
2015-02-17T03:30:24.020Z
2015-02-17T03:30:24.020Z
Moin Qidwai
<p>Try using <code>|without</code> based on arrays of user IDs, not entire UserModel objects. Behind the scenes, it's just using PHP's <a href="http://php.net/manual/en/function.in-array.php" rel="nofollow">in_array</a> method, which works much better on simple primitives like ints, strings, etc. instead of complex objects like Models (that has magic methods, other objects, primitives, etc.).  in_array probably doesn't know how deep of a comparison to make on those objects.</p>

CC BY-SA 3.0
2015-02-16T20:55:22.240Z
Ok I will try that, strange that it's working on one but not the other array (both of which contain the same data).
Sam Hibberd
CC BY-SA 3.0
2015-02-16T18:01:31.957Z
2015-02-16T18:01:31.957Z
Brad Bell
<p>I am using the Dukt Follow plugin to return 2 arrays which both hold User objects, I am then using the without filter to remove users from the array which are considered friends. Friends are determined by using the intersect filter on the 2 arrays.</p>

<p>Everything works apart from the second without filter which does not work, and returns objects that are in the friends array.</p>

<pre><code>{# Friends, Followers &amp; Following #}
{% set userFollowing = craft.follow.getFollowing(user.id) %}
{% set userFollowers = craft.follow.getFollowers(user.id) %}

{% set friends = userFollowing|length and userFollowers|length ? userFollowing|intersect(userFollowers) : null %}
{% set following = userFollowing|without(friends) %}
{% set followers = userFollowers|without(friends) %}
</code></pre>

<p>Is there an obvious reason why this might not be working?
How is best to debug something like this?</p>

<p>I have checked the output of all the arrays and objects and they do appear to hold the data that they should. </p>

<p>Basic data stored in each array:</p>

<pre><code>User Following:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn","Craft\\UserModel: shorn"]

User Followers:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn"]

Friends:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn"]

Following:
Array: {"2":"Craft\\UserModel: shorn"}

Followers:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn"]
</code></pre>

<p>Full variable output can be accessed here: <a href="http://cl.ly/2o292X3O2r0M" rel="nofollow">http://cl.ly/2o292X3O2r0M</a></p>

CC BY-SA 3.0
2015-02-16T10:43:29.770Z
Cannot really reproduce this. Would be helpful if you could post the data inside friends, userFollowing and userFollowers.
Moin Qidwai
CC BY-SA 3.0
2015-02-16T16:52:47.527Z
A bit confused — the output data that you posted contains 'userFollowing', 'userFollowers' (neither of which intersect btw), and 'friends' — not 'following', 'followers', and 'friends' as I would expect. Keep in mind that the `without` filter is returning a copy of the array — not modifying the original. In principle, this should work though. You might have something else going on with your data — I would check the values again carefully.
Douglas McDonald
CC BY-SA 3.0
2015-02-16T17:33:09.717Z
The data provided contains what was requested, can you confirm what you mean by 'neither of which intersect btw'? The friends array does return the required users which are in both arrays hence following each other?
Sam Hibberd
CC BY-SA 3.0
2015-02-16T17:45:37.263Z
@DouglasMcDonald I have added more debug data, does this help explain the issue any better?
Sam Hibberd
<templating><filter>
Why is the Craft without filter not working correctly and how to debug?
# Why is the Craft without filter not working correctly and how to debug?

(Asked by: username_0 on 2015-02-16)

I am using the Dukt Follow plugin to return 2 arrays which both hold User objects, I am then using the without filter to remove users from the array which are considered friends. Friends are determined by using the intersect filter on the 2 arrays.
Everything works apart from the second without filter which does not work, and returns objects that are in the friends array.
{# Friends, Followers & Following #}
{% set userFollowing = craft.follow.getFollowing(user.id) %}
{% set userFollowers = craft.follow.getFollowers(user.id) %}

{% set friends = userFollowing|length and userFollowers|length ? userFollowing|intersect(userFollowers) : null %}
{% set following = userFollowing|without(friends) %}
{% set followers = userFollowers|without(friends) %}

Is there an obvious reason why this might not be working?
How is best to debug something like this?
I have checked the output of all the arrays and objects and they do appear to hold the data that they should. 
Basic data stored in each array:
User Following:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn","Craft\\UserModel: shorn"]

User Followers:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn"]

Friends:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn"]

Following:
Array: {"2":"Craft\\UserModel: shorn"}

Followers:
Array: ["Craft\\UserModel: bencallaway","Craft\\UserModel: davidwearn"]

Full variable output can be accessed here: http://cl.ly/2o292X3O2r0M

**Tags:** templating, filter
> **Comments:**
> **username_1**: Cannot really reproduce this. Would be helpful if you could post the data inside friends, userFollowing and userFollowers.  
> **username_2**: A bit confused — the output data that you posted contains 'userFollowing', 'userFollowers' (neither of which intersect btw), and 'friends' — not 'following', 'followers', and 'friends' as I would expect. Keep in mind that the `without` filter is returning a copy of the array — not modifying the original. In principle, this should work though. You might have something else going on with your data — I would check the values again carefully.  
> **username_0**: The data provided contains what was requested, can you confirm what you mean by 'neither of which intersect btw'? The friends array does return the required users which are in both arrays hence following each other?  
> **username_0**: @DouglasMcDonald I have added more debug data, does this help explain the issue any better?  

---

## 2 answers

### Answer by username_1 on 2015-02-17. Score: 1

Hey Sam the answer is in your own dump file. Just look at the userModel Numbers in userFollowing, userFollowers and friends.

UserFollowing has [379, 381, 393],
UserFollowers has [446, 454] and
friends has [379, 381]

Friends has the same numbers as userFollowing but not the same as userFollowers. Hence when you do the without filter on userFollowers you are basically doing
[446, 454]|without([379, 381])
Which will ofcourse return [446, 454].

You could ofcourse get the username out for each model and perform the operations on that and since those would be strings this would work.

> **Comments:**
> **username_0**: Ah, exactly what I've been trying to get my head around. So do model numbers not relate to the user object?  
> **username_1**: You are correct. There is no connection between model number and user model. The same user can have different model numbers at different times because each time a new model will be created for that user.  You can even try this to see the model number change on each refresh: {{ dump(craft.users.first()) }}  

---

### Answer by username_3 on 2015-02-16. Score: 1

Try using `|without` based on arrays of user IDs, not entire UserModel objects. Behind the scenes, it's just using PHP's [in\_array](http://php.net/manual/en/function.in-array.php) method, which works much better on simple primitives like ints, strings, etc. instead of complex objects like Models (that has magic methods, other objects, primitives, etc.). in\_array probably doesn't know how deep of a comparison to make on those objects.

> **Comments:**
> **username_0**: Ok I will try that, strange that it's working on one but not the other array (both of which contain the same data).  

---

