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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Either product_id is nil or wrong?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162797" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-162797" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162797"
                     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 #11"></div>
  </section>
</div>
    <div class="postbit" id="162798" data-post-id="162798">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="shijith.k" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shijith.k/120/18420_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  shijith.k
                    <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>I doubt its because I am using Ecto.Multi. Because multi dont create the product until all the functions run perfectly, right? Correct me if I am wrong</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162798" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-162798" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162798"
                     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 #12"></div>
  </section>
</div>
    <div class="postbit" id="162885" data-post-id="162885">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Sorry for the late answer but I changed the code to:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def tag_product(product, %{tag: tag_attrs} = attrs) do
    tag = create_or_find_tag(tag_attrs)

    product
    |&gt; Ecto.build_assoc(:taggings)
    |&gt; Tagging.changeset(attrs)
    |&gt; Ecto.Changeset.put_assoc(:tag, tag)
    |&gt; Repo.insert()
  end

  defp create_or_find_tag(%{name: "" &lt;&gt; name} = attrs) do
    %Tag{}
    |&gt; Tag.changeset(attrs)
    |&gt; Repo.insert()
    |&gt; case do
      {:ok, tag} -&gt; tag
      _ -&gt; Repo.get_by(Tag, name: name)
    end
  end
  defp create_or_find_tag(_), do: nil
</code></pre>
<p>And test:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    test "tag_product/2 with valid data appends the tag if it exists" do
      product = product_fixture()
      tag = tag_fixture()
      Taggable.delete_tag_from_product(product, tag)

      assert {:ok, %Tagging{} = tagging} = Taggable.tag_product(product, %{tag: %{name: "Stout"}})
      assert tagging.tag.name == "Stout"
    end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162885" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-162885" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162885"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="162891" data-post-id="162891">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="shijith.k" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shijith.k/120/18420_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  shijith.k
                    <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>I checked your GitHub code, and there is a cast_assoc in the taggings Changeset function, and in the tag_product function you have added another put_assoc too. Can you please explain me your code?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162891" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-162891" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162891"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="162894" data-post-id="162894">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="shijith.k" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shijith.k/120/18420_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  shijith.k
                    <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">
								<aside class="quote no-group" data-username="shijith.k" data-post="11" data-topic="29000" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shijith.k/48/18420_2.png" class="avatar"> shijith.k:</div>
<blockquote>
<p>also, i keep getting this error,</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">* (Ecto.ConstraintError) constraint error when attempting to insert struct:

    * taggings_product_id_fkey (foreign_key_constraint)
</code></pre>
</blockquote>
</aside>
<p>Also, this was because I used <code>Task.async_stream</code> to iterate over the list of tags and bind them to the product.<br>
I changed it to <code>Stream.map</code> and now it works fine. Any idea, why <code>Task.async_stream</code> causes this error? <a class="mention" href="/u/andreaseriksson" rel="nofollow">@andreaseriksson</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162894" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-162894" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162894"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="162895" data-post-id="162895">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="shijith.k" data-post="15" data-topic="29000" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shijith.k/48/18420_2.png" class="avatar"> shijith.k:</div>
<blockquote>
<p>I checked your GitHub code, and there is a cast_assoc in the taggings Changeset function, and in the tag_product function you have added another put_assoc too. Can you please explain me your code?</p>
</blockquote>
</aside>
<p>I tried to remove it but one of the test cases failed (raised) instead of returning an error changeset. But maybe that scenario would never happen if you design your UI correct</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162895" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-162895" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162895"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="162896" data-post-id="162896">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="shijith.k" data-post="16" data-topic="29000">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shijith.k/48/18420_2.png" class="avatar"> shijith.k:</div>
<blockquote>
<p>I changed it to <code>Stream.map</code> and now it works fine. Any idea, why <code>Task.async_stream</code> causes this error?</p>
</blockquote>
</aside>
<p>Im guessing since there are database constraints and you running the inserts async, the references are not persisted at this point? Or the current process doesn’t know about it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162896" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-162896" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162896"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="162984" data-post-id="162984">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/shijith.k" rel="nofollow">@shijith.k</a> Did everything work out for you?</p>
<p>I also added a second part where I have an interface for adding the tags:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://fullstackphoenix.com/tutorials/tagging-interface-with-phoenix-liveview-and-tailwind-tagging-part-2">
  <header class="source">

      <a href="https://fullstackphoenix.com/tutorials/tagging-interface-with-phoenix-liveview-and-tailwind-tagging-part-2" target="_blank" rel="noopener nofollow ugc" title="12:00AM - 13 February 2020">FullstackPhoenix – 13 Feb 20</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:600/315;"><img src="https://res.cloudinary.com/dwvh1fhcg/image/upload/w_600,c_scale/v1700161528/ah1vu6vccdvganbt0o2g.jpg" class="thumbnail" alt="" width="600" height="315"></div>

<h3><a href="https://fullstackphoenix.com/tutorials/tagging-interface-with-phoenix-liveview-and-tailwind-tagging-part-2" target="_blank" rel="noopener nofollow ugc">Tagging interface with Phoenix LiveView and Tailwind - Tagging part 2</a></h3>

  <p>In the previous tutorial, I set up the the backend for being able to add tags to products. I have also written a tutorial about adding a LiveView and Tailwind typeahead. This will basically be very si</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="162984" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-162984" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="162984"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="163009" data-post-id="163009">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="shijith.k" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shijith.k/120/18420_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  shijith.k
                    <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>Yes, everything worked out. But I didn’t use  <code>cast_assoc </code> is taggings changeset.</p>
<p>I will check the second part of the tutorial.</p>
<p>If you dont mind, can we have a chat in slack or telegram? I have some doubts</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="163009" 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/unique-constraint-error-on-a-schema-less-many-to-many-association-table/29000/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-163009" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="163009"
                     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>