in Education by
having this code block of an example rails model class: class Block < ActiveRecord::Base has_many :bricks, :autosave => true def crunch bricks.each do |brick| if brick.some_condition? brick.name = 'New data' brick.save # why do I have to call this? end end end end class Brick < ActiveRecord::Base belongs_to :block, :autosave => true end I found that the only way to make sure the changes within the associated objects get saved for me, was to call brick.save manually. Even thought I use :autosave => true Why? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Probably the autosave option has a misleading name. By the way, it's the expected behaviour. The option is meant for association. So if you modify an object in a relation and save the other object then ActiveRecord saves the modified objects. So, in your case, you could change your code to: def crunch bricks.each do |brick| if brick.some_condition? brick.name = 'New data' end end save # saving the father with autosave should save the children end

Related questions

0 votes
    I have following Comments-on-Models design (source: http://railscasts.com/episodes/154-polymorphic-association): ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    If I have a "Bill" entity, I might create that bill instance via REST API by assigning the food ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    If I have a "Bill" entity, I might create that bill instance via REST API by assigning the food ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have this example code which raises a "Duplicate Expection". Instead, I want just to skip if a duplicate exists. (1..10).each do |page| group.products...
asked May 26, 2022 in Education by JackTerrance
0 votes
    How to get the class object of associated class using Reflection? (a) Class.forName( className ) (b) Class.name( ... JSP & API of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
0 votes
    If you have a lot of objects that you want to save to a file, we use ________ function. (a) save() ... and Operations of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    If we want to save individual R objects to a file, we use the _______ function. (a) save() (b) save ... and Operations of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which of the following is an example of Changing Operating Model? (1)Enterprise Transformation (2)Management Transformation (3)IT Transformation (4)Business Process Transformation...
asked Sep 21, 2021 in Technology by JackTerrance
0 votes
    I am searching for the better option to save a trained model in PyTorch, these are the options I am using ... the above two functions? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    In Ruby on Rails Development (or MVC in general), what quick rule should I follow as to where to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 31, 2022 in Education by JackTerrance
0 votes
    The RoR tutorials posit one model per table for the ORM to work. My DB schema has some 70 tables ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I have a user model that has many fields (let's say 30 for this example). When the user signs ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    So the problem is i don't get get a value from textbox field on GridView RowUpdating event. Here ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    What's the easiest way to get the filename associated with an open HANDLE in Win32? JavaScript questions ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
...