Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on rails application with multiple models
    text
    copied!<p>I have a few small ROR "mostly static" type sites and am working on something a little deeper that I don't have much experience with...</p> <p>The BIG picture nomenclature. Accounts have many users and projects. users have many projects. users add many files and notes to projects....</p> <p>In the end I need to generate a view where users can see their projects, files, &amp; notes. In a list or table similar to the MANUALLY created "proof of concept" one below:</p> <pre><code>Project1 Notes note1 note2 note3 Files file1 file2 file2 Users user1 user2 Project2 Notes note1 note2 note3 Files file1 file2 file2 Users user1 user2 </code></pre> <p>The list above will be generated using some sort of an embedded ruby for loop but before I get into that I need to ensure I have the proper model associations and calls.</p> <p>I'm attempting to have NO foreign keys from all my tables but I've been getting really confused with multi-model best practices. With no foreign keys I THINK I need a join table, which could be a model using "model1_model2" naming convention?, and the ":through" model relationship?</p> <p>my models now (this has been changing alot) are:</p> <p>Account:</p> <pre><code>class Account &lt; ActiveRecord::Base has_many :projects has_many :users </code></pre> <p>end</p> <p>User:</p> <pre><code>class User &lt; ActiveRecord::Base has_one :account has_many :projects, :through =&gt; :accounts has_many :dataFiles, :through =&gt; :projects has_many :notes, :through =&gt; :projects </code></pre> <p>end</p> <p>Project:</p> <pre><code>class Project &lt; ActiveRecord::Base belongs_to :account has_many :users has_many :datafiles has_many :notes </code></pre> <p>end</p> <p>DataFile:</p> <pre><code>class DataFile &lt; ActiveRecord::Base belongs_to :projects belongs_to :users </code></pre> <p>end</p> <p>Note:</p> <pre><code>class Note &lt; ActiveRecord::Base belongs_to :project belongs_to :users </code></pre> <p>end</p> <p>As you can probably see; I'm confused here! I've done a bunch of tutorials and read a book; this is my first real world application that isn't just mainly static pages....</p> <p>There appears to be a lot of ways this could be done. I guess I'm looking for some expert direction on what models I should use and how I should connect them. </p> <p>Any direction or advice you can offer is greatly appreciated. Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload