Im looking for a good way to solve my performance issues in my rails application. I have three tables which have: one to one to many connections in between. If I want to fill in 130 items of the first table with all the data for the underneath tables, It results in about 1000 queries and takes about 10 seconds (SQLite DB).
I found the
accept_nested_attributes_for
statement, witch lets you enter data for multiple tables in one line of code. My question is, wether this is a good option in a performance point of view. Does somebody have any experience with it?
Thanks
Markus
accept_nested_attributes_for add the possibility to ActiveRecord to be able to write into association directly from one model.
exemple :
You have models like :
and a hash like :
This will create a new user and a new car,
without accepts_nested_attributes_for :
This function is usually with fields_for in HTML forms so you can easily handle the creation of an object and his associations.
In your case I imagine your models like that (regarding your XML) :
I don’t know where your XML come from (your data are extracted from it ??), but I imagine you could use accepts_nested_attributes_for so you could have each card hash generating the associations.
But I’m not sure to understand all the problem and if this is the best solution