Hi All,
I am inserting data from one table to another by using following method
@data=RoyaltyReportFiles.find_by_sql(“insert into royalty_reports
(artist_name, album_name) select artist_name, album_name from
temp_royalty_reports where id=328417”)
it saves the data into royalty_reports table but it gives following
error and application crashes. i am using rails 1.2.5
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.all_hashes
I am inserting data from one table to another by using following method
@data=RoyaltyReportFiles.find_by_sql(“insert into royalty_reports
(artist_name, album_name) select artist_name, album_name from
temp_royalty_reports where id=328417”)
Use either count_by_sql(), execute(), or the method higher than
execute() whose
name I forget…
Also, AR can insert one record for you very easily…
Use either count_by_sql(), execute(), or the method higher than
execute() whose
name I forget…
Also, AR can insert one record for you very easily…
Actually i’m trying to insert multiple data from one table to another
table but i take only one data here for example.
i try ar-extensions but as i’m using rails 1.2.0 it gives me following
error
undefined method `expand_hash_conditions_for_aggregates’ for
#Class:0x4593c48
which is related to the ar-extensions , activerecord gem
i also like to know how to use the count_by_sql(), execute() method
Hi All,
I am inserting data from one table to another by using following method
@data=RoyaltyReportFiles.find_by_sql(“insert into royalty_reports
(artist_name, album_name) select artist_name, album_name from
temp_royalty_reports where id=328417”)
That’s not a good idea. When you use find_by_sql, rails will try and
create a result set array (because it assumes you are doing a select).
RoyaltyReportFiles.connection.execute allows you to execute arbitrary
sql, however if you are doing an insert you should use
RoyaltyReportFiles.connection.insert ( the only difference is
readability and the fact that insert will flush Rails’ query cache
whereas execute will not).
That’s not a good idea. When you use find_by_sql, rails will try and
create a result set array (because it assumes you are doing a select).
RoyaltyReportFiles.connection.execute allows you to execute arbitrary
sql, however if you are doing an insert you should use
RoyaltyReportFiles.connection.insert ( the only difference is
readability and the fact that insert will flush Rails’ query cache
whereas execute will not).
Fred
Hi Fred,
thanks a million. it works…
I write a following code and it works like a magic…