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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BryanJBryce" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BryanJBryce/120/11560_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BryanJBryce
                    <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>For the benefit of future generations here is the new action used by <code>Shift.start/</code> to create <code>EmployeeShift</code>s from an array of <code>employee_ids</code> just after the <code>Shift</code> is created:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  create :start_from_shift do
      primary? true
      accept [:employee_id]

      argument :employee_id, :uuid, allow_nil?: false

      change set_attribute(:employee_id, arg(:employee_id))
      change set_attribute(:in_at, DateTime.utc_now())
    end
</code></pre>
<p>This is the action that calls it:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  create :start do
      primary? true
      accept [:till_id, :employee_ids]

      argument :till_id, :uuid, allow_nil?: false
      argument :employee_ids, {:array, :uuid}, allow_nil?: false

      change set_attribute(:start_at, DateTime.utc_now())
      change set_attribute(:till_id, arg(:till_id))

      change manage_relationship(:employee_ids, :employee_shifts,
               type: :create,
               value_is_key: :employee_id
             )
    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="317174" 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/custom-action-using-manage-relationship-when-relationship-is-many-to-many/61517/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-317174" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="317174"
                     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="317186" data-post-id="317186">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BryanJBryce" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BryanJBryce/120/11560_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BryanJBryce
                    <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="BryanJBryce" data-post="11" data-topic="61517">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bryanjbryce/48/11560_2.png" class="avatar"> BryanJBryce:</div>
<blockquote>
<p>Does it always use the primary action or is there a way to specify?</p>
</blockquote>
</aside>
<p>Looks like maybe doesn’t support specifying the action to use, but just uses the primary:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"> change manage_relationship(:employee_ids, :employee_shifts,
               type: :create,
               action: :start_from_shift,
               value_is_key: :employee_id
             )
</code></pre>
<blockquote>
<p>** (NimbleOptions.ValidationError) unknown options [:action], valid options are: [:type, :authorize?, :eager_validate_with, :on_no_match, :value_is_key, :identity_priority, :use_identities, :on_lookup, :on_match, :on_missing, :error_path, :meta, :ignore?]</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="317186" 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/custom-action-using-manage-relationship-when-relationship-is-many-to-many/61517/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-317186" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="317186"
                     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="317188" data-post-id="317188">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zachdaniel" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/120/31980_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zachdaniel
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Ash</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The action is specified by modifying the underlying keys for <code>manage_relationship</code>.</p>
<p><code>type: :create</code> maps to</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">[
  on_no_match: :create,
  on_match: :ignore
]
</code></pre>
<p>The docs for it are here: <a href="https://hexdocs.pm/ash/Ash.Changeset.html#manage_relationship/4" class="inline-onebox" rel="noopener nofollow ugc">Ash.Changeset — ash v3.29.3</a></p>
<p>So you’d say:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">type: :create,
on_match: {:create, :action_name, :join_table_action_name, []}
</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="317188" data-batch-url="/posts/batch_likers">
                        3
                      </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/custom-action-using-manage-relationship-when-relationship-is-many-to-many/61517/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-317188" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="317188"
                     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="317190" data-post-id="317190">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BryanJBryce" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BryanJBryce/120/11560_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BryanJBryce
                    <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>Perfect, thank you <img src="https://forum.elixirforum.com/images/emoji/apple/folded_hands.png?v=15" title=":folded_hands:" class="emoji" alt=":folded_hands:" loading="lazy" width="20" height="20"> <img src="https://forum.elixirforum.com/images/emoji/apple/partying_face.png?v=15" title=":partying_face:" class="emoji" alt=":partying_face:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="317190" 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/custom-action-using-manage-relationship-when-relationship-is-many-to-many/61517/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-317190" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="317190"
                     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="317200" data-post-id="317200">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BryanJBryce" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BryanJBryce/120/11560_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BryanJBryce
                    <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 group-Ash-Core-Team" data-username="zachdaniel" data-post="14" data-topic="61517">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/48/31980_2.png" class="avatar"> zachdaniel:</div>
<blockquote>
<p><code>on_match: {:create, :action_name, :join_table_action_name, []}</code></p>
</blockquote>
</aside>
<p>I think this should be <code>on_no_match</code>, 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="317200" 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/custom-action-using-manage-relationship-when-relationship-is-many-to-many/61517/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-317200" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="317200"
                     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="317201" data-post-id="317201">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BryanJBryce" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BryanJBryce/120/11560_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BryanJBryce
                    <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>So the action on <code>EmployeeShift</code> is no longer primary so it looks like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"> create :start_from_shift do
      accept [:employee_id]

      argument :employee_id, :uuid, allow_nil?: false

      change set_attribute(:employee_id, arg(:employee_id))
      change set_attribute(:in_at, DateTime.utc_now())
    end
</code></pre>
<p>And the <code>manage_relationship</code> action in <code>Shift</code> now looks like this, with the updated specification for when we go to create, there is no match (which should always be true), I specify that I want to use the <code>:create</code> action called <code>:start_from_shift</code>.</p>
<p>Since I’m doing this through the <code>has_many</code> and not the <code>many_to_many</code>, I’m not specifying a join table action name, just the action name and since I’m providing a list of UUIDs I specify that those values are for using as the <code>employee_id</code> parameter that the <code>:start_from_shift</code> action requires.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"> change manage_relationship(:employee_ids, :employee_shifts,
               type: :create,
               on_no_match: {:create, :start_from_shift},
               value_is_key: :employee_id
             )
</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="317201" 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/custom-action-using-manage-relationship-when-relationship-is-many-to-many/61517/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-317201" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="317201"
                     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="317206" data-post-id="317206">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zachdaniel" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachdaniel/120/31980_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zachdaniel
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Ash</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ah, yeah typo on my part <img src="https://forum.elixirforum.com/images/emoji/apple/+1.png?v=15" title=":+1:" class="emoji" alt=":+1:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="317206" 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/custom-action-using-manage-relationship-when-relationship-is-many-to-many/61517/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-317206" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="317206"
                     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>