Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple database tables within one AR model in Rails 3
    primarykey
    data
    text
    <p>I was asked to make some kind of reporting (logging) service. The employee has locally installed web application (just some dynamic website, written in PHP) in many companies. This web app is some kind of survey. All data is saved on local database, but now the requirement is that this data (result of survey) will also be sent to central server after every form submit.</p> <p>There are four types of surveys. They have organised it this way, that there are many Projects, and each Project can have only one Survey of each type (STI here?) and Survey belongs to one Project. Each Survey will receive a report from local app, so it will have many Reports. The Rails 3 app that logs this reports should mimic somehow this logic. First question is: does this AR structure make sense for you?</p> <pre><code> Project-1--------1-Survey-1-------*-Report Project has_one :survey has_many :reports, :through =&gt; :survey Survey belongs_to :project has_many :reports Report belongs_to :survey </code></pre> <p>Second question is about having multiple tables for one AR Model. If all data will be stored in <code>reports</code> table, the table will become huge very quickly, and efficient querying for reports that belong to specific survey might be a problem after some time. Maybe it would be better to have separate tables for each Survey? Like <code>reports_&lt;survey_id&gt;</code>. Is this possible?</p> <p>Also, I am somehow forced to use MySQL, but if there is another, much better solution for this, I could try to push it through.</p> <p>If you are still here, thank you for reading this :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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