Having a problem figuring out how to structure this... Nesting issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Having a problem figuring out how to structure this... Nesting issue

John Sanderbeck
I'm working on a project that has the following setup

I have a table called Assessment

for each assessment there can be different reasons and consequences defined for that assessment

then for each assessment the teacher takes multiple data entries over a period of time

each data entry can choose multiple reasons and consequences from the ones defined in the assessment

So you have assessment
has_many :reasons
accepts_nested_attributes_for :reasons
has_many :consequences
accepts_nested_attributes_for :consequences
has_many :data_entries
accepts_nested_attributes_for :data_entries

Then reasons
belongs_to :assessment
has_and_belongs_to_many :data_entries

Then consequences
belongs_to :assessment
has_and_belongs_to_many :data_entries

Finally data_entries
belong to assessment
has_and_belongs_to_many :reasons
has_and_belongs_to_many :consequences

There is also a join table for reasons to data_entries, and consequences to data_entries

The nested table works fine for the reasons, consequences, and the base data_entries

however what I cannot get to work is the reasons and consequences chosen in the data_entries

what appears to be happening in params is that assessment comes back with data_entries_attributes under it
however there is also a data_entry param coming back as well, so it is not part of assessment, so the nest is wrong somehow...

I have this working in other places however this nest is one level deeper than the others...

The way I have the nested form section setup is this...

  <td>
    <div class="multi-column">
      <ul>
        <% @assessment.reasons.each do |reason| -%>
            <ul>
              <%= check_box_tag('data_entry[reason_ids][]', reason.id, @assessment.reason_ids.include?(reason.id), :multiple => true) %>
              <span rel="tooltip" title="<%= reason.assessment_id %>"><%= reason.name %></span>
            </ul>
        <% end %>
      </ul>
    </div>
  </td>
  <td>
    <div class="multi-column">
      <ul>
        <% @assessment.consequences.each do |consequence| -%>
            <ul>
              <%= check_box_tag('data_entry[consequence_ids][]', consequence.id, @assessment.consequence_ids.include?(consequence.id), :multiple => true) %>
              <span rel="tooltip" title="<%= consequence.assessment_id %>"><%= consequence.name %></span>
            </ul>
        <% end %>
      </ul>
    </div>
  </td>


John

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/dbec31d4-3180-4f9d-ad39-31e4897a6ab1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Having a problem figuring out how to structure this... Nesting issue

Colin Law
On Wed, 24 Oct 2018 at 12:12, John Sanderbeck <[hidden email]> wrote:

>
> I'm working on a project that has the following setup
>
> I have a table called Assessment
>
> for each assessment there can be different reasons and consequences defined for that assessment
>
> then for each assessment the teacher takes multiple data entries over a period of time
>
> each data entry can choose multiple reasons and consequences from the ones defined in the assessment
>
> So you have assessment
> has_many :reasons
> accepts_nested_attributes_for :reasons
> has_many :consequences
> accepts_nested_attributes_for :consequences
> has_many :data_entries
> accepts_nested_attributes_for :data_entries
>
> Then reasons
> belongs_to :assessment
> has_and_belongs_to_many :data_entries

If I understand the problem correctly then you don't need that, you
can do has_many data_entries through assessment and in data_entries
the same thing the other way round. That is assuming that all the
data_entries for a reason are those defined for the assessment it
belongs to. Then to get the data_entries for a reason you use
reason.assesment.data_entries.  Similarly for the other classes.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLt9zYe9W6meSZayaBctQPy-i1he__3NGtLXwG%2BHL1zf6Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Having a problem figuring out how to structure this... Nesting issue

John Sanderbeck
In reply to this post by John Sanderbeck
Hmmm...   That may work...

I would always be accessing assessment.data_entries for any lists or views. Reasons and Consequences are basically select criteria for each data entry.
I would never reference reason.data_entries or consequence.data_entries

a has_many :data_entries, :through: :assessment may work though...  Let me give that a shot...

Now to figure out how to structure it...  :-)

On Wednesday, October 24, 2018 at 7:12:45 AM UTC-4, John Sanderbeck wrote:
I'm working on a project that has the following setup

I have a table called Assessment

for each assessment there can be different reasons and consequences defined for that assessment

then for each assessment the teacher takes multiple data entries over a period of time

each data entry can choose multiple reasons and consequences from the ones defined in the assessment

So you have assessment
has_many :reasons
accepts_nested_attributes_for :reasons
has_many :consequences
accepts_nested_attributes_for :consequences
has_many :data_entries
accepts_nested_attributes_for :data_entries

Then reasons
belongs_to :assessment
has_and_belongs_to_many :data_entries

Then consequences
belongs_to :assessment
has_and_belongs_to_many :data_entries

Finally data_entries
belong to assessment
has_and_belongs_to_many :reasons
has_and_belongs_to_many :consequences

There is also a join table for reasons to data_entries, and consequences to data_entries

The nested table works fine for the reasons, consequences, and the base data_entries

however what I cannot get to work is the reasons and consequences chosen in the data_entries

what appears to be happening in params is that assessment comes back with data_entries_attributes under it
however there is also a data_entry param coming back as well, so it is not part of assessment, so the nest is wrong somehow...

I have this working in other places however this nest is one level deeper than the others...

The way I have the nested form section setup is this...

  <td>
    <div class="multi-column">
      <ul>
        <% @assessment.reasons.each do |reason| -%>
            <ul>
              <%= check_box_tag('data_entry[reason_ids][]', <a href="http://reason.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;">reason.id, @assessment.reason_ids.include?(<a href="http://reason.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;">reason.id), :multiple => true) %>
              <span rel="tooltip" title="<%= reason.assessment_id %>"><%= <a href="http://reason.name" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNESbwm6L4x_vLasBu1Qjjubst9H1w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNESbwm6L4x_vLasBu1Qjjubst9H1w&#39;;return true;">reason.name %></span>
            </ul>
        <% end %>
      </ul>
    </div>
  </td>
  <td>
    <div class="multi-column">
      <ul>
        <% @assessment.consequences.each do |consequence| -%>
            <ul>
              <%= check_box_tag('data_entry[consequence_ids][]', <a href="http://consequence.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;">consequence.id, @assessment.consequence_ids.include?(<a href="http://consequence.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;">consequence.id), :multiple => true) %>
              <span rel="tooltip" title="<%= consequence.assessment_id %>"><%= <a href="http://consequence.name" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrN2CK4SkaL-hkcyi7jfNbZWCwrQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrN2CK4SkaL-hkcyi7jfNbZWCwrQ&#39;;return true;">consequence.name %></span>
            </ul>
        <% end %>
      </ul>
    </div>
  </td>


John

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/749f9533-d198-4f8a-a2a5-98c6c5368452%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Having a problem figuring out how to structure this... Nesting issue

Colin Law
Certainly you only need to specify the associations you need to use.

Colin
On Wed, 24 Oct 2018 at 14:44, John Sanderbeck <[hidden email]> wrote:

>
> Hmmm...   That may work...
>
> I would always be accessing assessment.data_entries for any lists or views. Reasons and Consequences are basically select criteria for each data entry.
> I would never reference reason.data_entries or consequence.data_entries
>
> a has_many :data_entries, :through: :assessment may work though...  Let me give that a shot...
>
> Now to figure out how to structure it...  :-)
>
> On Wednesday, October 24, 2018 at 7:12:45 AM UTC-4, John Sanderbeck wrote:
>>
>> I'm working on a project that has the following setup
>>
>> I have a table called Assessment
>>
>> for each assessment there can be different reasons and consequences defined for that assessment
>>
>> then for each assessment the teacher takes multiple data entries over a period of time
>>
>> each data entry can choose multiple reasons and consequences from the ones defined in the assessment
>>
>> So you have assessment
>> has_many :reasons
>> accepts_nested_attributes_for :reasons
>> has_many :consequences
>> accepts_nested_attributes_for :consequences
>> has_many :data_entries
>> accepts_nested_attributes_for :data_entries
>>
>> Then reasons
>> belongs_to :assessment
>> has_and_belongs_to_many :data_entries
>>
>> Then consequences
>> belongs_to :assessment
>> has_and_belongs_to_many :data_entries
>>
>> Finally data_entries
>> belong to assessment
>> has_and_belongs_to_many :reasons
>> has_and_belongs_to_many :consequences
>>
>> There is also a join table for reasons to data_entries, and consequences to data_entries
>>
>> The nested table works fine for the reasons, consequences, and the base data_entries
>>
>> however what I cannot get to work is the reasons and consequences chosen in the data_entries
>>
>> what appears to be happening in params is that assessment comes back with data_entries_attributes under it
>> however there is also a data_entry param coming back as well, so it is not part of assessment, so the nest is wrong somehow...
>>
>> I have this working in other places however this nest is one level deeper than the others...
>>
>> The way I have the nested form section setup is this...
>>
>>   <td>
>>     <div class="multi-column">
>>       <ul>
>>         <% @assessment.reasons.each do |reason| -%>
>>             <ul>
>>               <%= check_box_tag('data_entry[reason_ids][]', reason.id, @assessment.reason_ids.include?(reason.id), :multiple => true) %>
>>               <span rel="tooltip" title="<%= reason.assessment_id %>"><%= reason.name %></span>
>>             </ul>
>>         <% end %>
>>       </ul>
>>     </div>
>>   </td>
>>   <td>
>>     <div class="multi-column">
>>       <ul>
>>         <% @assessment.consequences.each do |consequence| -%>
>>             <ul>
>>               <%= check_box_tag('data_entry[consequence_ids][]', consequence.id, @assessment.consequence_ids.include?(consequence.id), :multiple => true) %>
>>               <span rel="tooltip" title="<%= consequence.assessment_id %>"><%= consequence.name %></span>
>>             </ul>
>>         <% end %>
>>       </ul>
>>     </div>
>>   </td>
>>
>>
>> John
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/749f9533-d198-4f8a-a2a5-98c6c5368452%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLumvKVAz7oB-dce3AkBrqBFn_oL0KONb16ho-cSpPAJcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Having a problem figuring out how to structure this... Nesting issue

John Sanderbeck
One question though...   For a through association, I have to have a join table for the association.

So since I want Assessment to be my parent, should I do a join like this?

Create a data_entry table and a data_records join table and then have the association be

assessment 

  has_many :data_entries, through: :data_records

and data_entries

  has_many :assessments, through: :data_records

However while this may be structured better, I would still have the issue with the reason and consequence associations...

John

On Wednesday, October 24, 2018 at 9:48:17 AM UTC-4, Colin Law wrote:
Certainly you only need to specify the associations you need to use.

Colin
On Wed, 24 Oct 2018 at 14:44, John Sanderbeck <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="-1lIGSEKBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">band...@...> wrote:

>
> Hmmm...   That may work...
>
> I would always be accessing assessment.data_entries for any lists or views. Reasons and Consequences are basically select criteria for each data entry.
> I would never reference reason.data_entries or consequence.data_entries
>
> a has_many :data_entries, :through: :assessment may work though...  Let me give that a shot...
>
> Now to figure out how to structure it...  :-)
>
> On Wednesday, October 24, 2018 at 7:12:45 AM UTC-4, John Sanderbeck wrote:
>>
>> I'm working on a project that has the following setup
>>
>> I have a table called Assessment
>>
>> for each assessment there can be different reasons and consequences defined for that assessment
>>
>> then for each assessment the teacher takes multiple data entries over a period of time
>>
>> each data entry can choose multiple reasons and consequences from the ones defined in the assessment
>>
>> So you have assessment
>> has_many :reasons
>> accepts_nested_attributes_for :reasons
>> has_many :consequences
>> accepts_nested_attributes_for :consequences
>> has_many :data_entries
>> accepts_nested_attributes_for :data_entries
>>
>> Then reasons
>> belongs_to :assessment
>> has_and_belongs_to_many :data_entries
>>
>> Then consequences
>> belongs_to :assessment
>> has_and_belongs_to_many :data_entries
>>
>> Finally data_entries
>> belong to assessment
>> has_and_belongs_to_many :reasons
>> has_and_belongs_to_many :consequences
>>
>> There is also a join table for reasons to data_entries, and consequences to data_entries
>>
>> The nested table works fine for the reasons, consequences, and the base data_entries
>>
>> however what I cannot get to work is the reasons and consequences chosen in the data_entries
>>
>> what appears to be happening in params is that assessment comes back with data_entries_attributes under it
>> however there is also a data_entry param coming back as well, so it is not part of assessment, so the nest is wrong somehow...
>>
>> I have this working in other places however this nest is one level deeper than the others...
>>
>> The way I have the nested form section setup is this...
>>
>>   <td>
>>     <div class="multi-column">
>>       <ul>
>>         <% @assessment.reasons.each do |reason| -%>
>>             <ul>
>>               <%= check_box_tag('data_entry[reason_ids][]', <a href="http://reason.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;">reason.id, @assessment.reason_ids.include?(<a href="http://reason.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGimYebGgcPF1R9nVMBcNFhxnUMtA&#39;;return true;">reason.id), :multiple => true) %>
>>               <span rel="tooltip" title="<%= reason.assessment_id %>"><%= <a href="http://reason.name" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNESbwm6L4x_vLasBu1Qjjubst9H1w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Freason.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNESbwm6L4x_vLasBu1Qjjubst9H1w&#39;;return true;">reason.name %></span>
>>             </ul>
>>         <% end %>
>>       </ul>
>>     </div>
>>   </td>
>>   <td>
>>     <div class="multi-column">
>>       <ul>
>>         <% @assessment.consequences.each do |consequence| -%>
>>             <ul>
>>               <%= check_box_tag('data_entry[consequence_ids][]', <a href="http://consequence.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;">consequence.id, @assessment.consequence_ids.include?(<a href="http://consequence.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFX-EJJdAwe7DgOs2zeOnM3I6zBgQ&#39;;return true;">consequence.id), :multiple => true) %>
>>               <span rel="tooltip" title="<%= consequence.assessment_id %>"><%= <a href="http://consequence.name" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrN2CK4SkaL-hkcyi7jfNbZWCwrQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fconsequence.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrN2CK4SkaL-hkcyi7jfNbZWCwrQ&#39;;return true;">consequence.name %></span>
>>             </ul>
>>         <% end %>
>>       </ul>
>>     </div>
>>   </td>
>>
>>
>> John
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="-1lIGSEKBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="-1lIGSEKBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/749f9533-d198-4f8a-a2a5-98c6c5368452%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/749f9533-d198-4f8a-a2a5-98c6c5368452%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/749f9533-d198-4f8a-a2a5-98c6c5368452%40googlegroups.com&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/749f9533-d198-4f8a-a2a5-98c6c5368452%40googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4c63b26a-3fa0-4c1e-b6a6-307166160a93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Having a problem figuring out how to structure this... Nesting issue

Colin Law
On Wed, 24 Oct 2018 at 23:21, John Sanderbeck <[hidden email]> wrote:
One question though...   For a through association, I have to have a join table for the association.

No, if you say
Reason has_many :data_entries, :through: :assessment
then since you already have reason belongs_to assessment so if you have a Reason in @reason then you can say
@assessment = @reason.assessment.
Also you already have assessment has_many data_entries so you can say
@data_entries = @assessment.data_entries
Therefore you can get direct from a reason to the associated data_entries using
@data_entries = @reason.assessment.data_entries
No need for an additional join table.

Have a look at the Rails Guide on Associations for more detail.
You might also like to work through the tutorial at railstutorial.org (which is free to use online) which should cover this and all the other basics of Rails.

Colin

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLt%2BJBvi%3DTXy_D5_eomavGyGaKFjLzBcaTv0v9rkdEHofg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.