title: Updating changeset through channel. It does not update..
body: <p>I have table of <code>Subcategory</code> and <code>Category</code>. <code>Subcategory</code> belongs to <code>Category</code> and <code>Category</code> has many <code>subcategory</code>. </p>
  
  <p>In <code>Category</code> table, there are <code>name</code> and <code>subcategory</code>, which is boolean.</p>
  
  <p>What I want to make is that when a user creates a subcategory, it checks whether there are unassigned food (which means a <code>food</code> is not assigned to any subcategories) and if there are not any unassigned food, it updates <code>subcategory</code> value of <code>Category</code> table to <code>true</code>. </p>
  
  <pre><code>def handle_in("create:subcategory", %{"name" =&gt; name, "category_id" =&gt; category_id}, socket) do 
  
   changeset = Subcategory.changeset(%Subcategory{name: name, category_id: String.to_integer(category_id)})
  |&gt;Repo.insert()
  
  unassignedfood = from(f in Myapp.Food, where: f.category_id == ^category_id and is_nil(f.subcategory_id), select: map(f, [:id, :name])) |&gt; Repo.all 
  
   if unassignedfood == nil do
    category = Repo.get!(Myapp.Category, category_id)
   |&gt; Myapp.Category.changeset(%{subcategory: true})
   |&gt; Repo.update!
  else
   category = Repo.get!(Myapp.Category, category_id)
   |&gt; Myapp.Category.changeset(%{subcategory: false})
   |&gt; Repo.update 
  end
  
   subcategories = from(p in Myapp.Subcategory, select: map(p, [:id, :name, :category_id])) |&gt; Repo.all
   response = %{subcategories: subcategories}
  
   broadcast! socket, "subcategories:updated", response
  
   {:noreply, socket}
  end
  </code></pre>
  
  <p>So I made code like above, if there are not unassigned food, change <code>subcategory</code> value of <code>Category</code> table to <code>true</code>. </p>
  
  <p>I checked that there are not <code>unassignedfood</code> but it does not update. </p>
  
  <p>Is this right way to do?? How can I fix this?</p>
  
  <p>Thanks in advance.. </p>