<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="45037" data-post-id="45037">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="maliawelli" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  maliawelli
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/gregvaughn" rel="nofollow">@gregvaughn</a>:<br>
True/false indicator would be the way, but I don’t know how to achieve this. I would be appreciated for help.</p>
<p>And second option (with 2nd query) was posted above, but I still don’t know, how to join single post from posts list with that sql result.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45037" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-45037" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45037"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="45040" data-post-id="45040">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="maliawelli" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  maliawelli
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/nobbz" rel="nofollow">@NobbZ</a>:</p>
<p>I’m really thankful for your attention.</p>
<p>Ok, let’s make it simplier. How to get in each post information if post is favourite or not? Let’s use virtual field:</p>
<blockquote>
<p>field :is_favourite, :integer, virtual: true</p>
</blockquote>
<p>But how to set this? At first we need to check if user is logged, so if (Guardian.Plug.current_resource(conn)). Can I use Guardian.Plug.current_resource(conn) in model?<br>
And later on, how to achieve is_favourite information?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45040" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-45040" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45040"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="45067" data-post-id="45067">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Since the field is now part of your struct, you can use update syntax to set its value:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">post = %{post | field: 1}
</code></pre>
<p>You can read that value by doing simple field access:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">value = post.is_favourite
</code></pre>
<p>I’m not sure though, what Guardian has to do with this…</p>
<hr>
<p><strong>edit</strong></p>
<p>I do consider the name (<code>is_favourite</code>) confusing for an integer field. In elixir the prefix <code>is_</code> and the suffix <code>?</code> are usually used for booleans, while the prefix <code>is_</code> is meaning “this is guardsafe”.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45067" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-45067" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45067"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="45074" data-post-id="45074">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="maliawelli" data-post="12" data-topic="7574">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/aeb1de/48.png" class="avatar"> maliawelli:</div>
<blockquote>
<p><a class="mention" href="/u/gregvaughn" rel="nofollow">@gregvaughn</a>:<br>
I can’t use join, because I won’t get posts which are not liked by logged user. I want to have only information in each post if it is liked by user or not.</p>
</blockquote>
</aside>
<p>Use left_join maybe?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45074" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-45074" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45074"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="45159" data-post-id="45159">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="maliawelli" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  maliawelli
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/nobbz" rel="nofollow">@NobbZ</a></p>
<blockquote>
<p>I’m not sure though, what Guardian has to do with this…</p>
</blockquote>
<p>If it is wrong, tell me how to get logged user data instead of Guardian? Mayby I’m wrong and there is simplier method.</p>
<p>You are right about boolean. So let’s assume:</p>
<blockquote>
<p>field :is_favourite, :boolean, virtual: true</p>
</blockquote>
<p>Still don’t have any idea how to iterate through posts to set this field true or false for each post. How can I achieve this?</p>
<p><a class="mention" href="/u/lostkobrakai" rel="nofollow">@LostKobrakai</a><br>
You are right. But with that code:<br>
In posts_controller:</p>
<blockquote>
<p>current_user = Guardian.Plug.current_resource(conn)<br>
page = Post.preload<br>
|&gt; Post.order_asc_by_insertion<br>
|&gt; Post.getFavourites2(current_user.id)<br>
|&gt; Repo.paginate(params)</p>
</blockquote>
<p>And in model:</p>
<blockquote>
<p>def getFavourites2(query, user_id) do<br>
from p in query,<br>
left_join: f in “posts_favourites”, on: f.post_id == p.id and f.user_id == ^user_id<br>
end</p>
</blockquote>
<p>I don’t have posts_favourites in output.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45159" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-45159" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45159"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #25"></div>
  </section>
</div>
    <div class="postbit" id="45161" data-post-id="45161">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="maliawelli" data-post="26" data-topic="7574">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/aeb1de/48.png" class="avatar"> maliawelli:</div>
<blockquote>
<p>If it is wrong, tell me how to get logged user data instead of Guardian? Mayby I’m wrong and there is simplier method.</p>
</blockquote>
</aside>
<p>Where do you store your logged in user data?  I just use the build-in Phoenix.Token on the Plug.Session.  Guardian is more useful for DB-less and remote API endpoints, not for a main website (it is significantly heavier than Phoenix.Token).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45161" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-45161" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45161"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #26"></div>
  </section>
</div>
    <div class="postbit" id="45178" data-post-id="45178">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="maliawelli" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  maliawelli
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/overminddl1" rel="nofollow">@OvermindDL1</a></p>
<p>Actually, I use it for API. I don’t have any views. I authenticate user by JWT. So I store all logged in user data in:</p>
<blockquote>
<p>Guardian.Plug.current_resource(conn)</p>
</blockquote> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45178" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-45178" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45178"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #27"></div>
  </section>
</div>
    <div class="postbit" id="45179" data-post-id="45179">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="maliawelli" data-post="28" data-topic="7574">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/aeb1de/48.png" class="avatar"> maliawelli:</div>
<blockquote>
<p>Actually, I use it for API. I don’t have any views. I atuhenticate user by JWT. So I store all logged in user data in:</p>
</blockquote>
</aside>
<p>Views doesn’t matter.</p>
<p>In essence:<br>
Is the remote server needing to authenticate with your server then Guardian is nice.<br>
Are you auth’ing local, then Phoenix.Token is better.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45179" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-45179" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45179"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #28"></div>
  </section>
</div>
    <div class="postbit" id="45181" data-post-id="45181">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="maliawelli" data-post="26" data-topic="7574">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/aeb1de/48.png" class="avatar"> maliawelli:</div>
<blockquote>
<p>If it is wrong, tell me how to get logged user data instead of Guardian? Mayby I’m wrong and there is simplier method.</p>
</blockquote>
</aside>
<p>You haven’t told anything about a logged in user before, anyway, that really doesn’t matter for your problem right now. We really have to keep it at a really basic level and should not overcomplicate it.</p>
<p>The main problems you have are iterating over a list while transforming each item into a list of separate results and how to deal with structs.</p>
<aside class="quote no-group" data-username="maliawelli" data-post="26" data-topic="7574">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/aeb1de/48.png" class="avatar"> maliawelli:</div>
<blockquote>
<p>Still don’t have any idea how to iterate through posts to set this field true or false for each post. How can I achieve this?</p>
</blockquote>
</aside>
<p>I have shown you how to do both in separate posts as you slowly uncovered your requirements. In germany we call this “salami tactics”, giving out stuff slice by slice…</p>
<p>In one post I introduced <code>Enum.map/2</code> to you, in another I introduced the map/struct-update syntax. Combining those, as both are basic building blocks of elixir, is left as an exercise to you.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45181" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/has-many-through-many-fields/7574/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-45181" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45181"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>