Tag Archives: ruby on rails

ActiveRecord from_xml (and from_json) part 2

This post is an upgrade to the previous post about the unmarshalling of XML and JSON strings into rails objects, with arbitrarily deep object associations. As you may know if you are reading this, there doesn’t seem to be a way in rails to reverse to_xml and to_json when associations are included. Example usage: xml [...]
Posted in rails | Also tagged , , , , | 9 Comments

ActiveRecord from_json and from_xml

(Edited 2 Sept 2011: Please see instead the updated post here: ActiveRecord from_xml (and from_json) part 2.) Unless I’m missing something, the default rails from_json and from_xml methods don’t work with data that have associated objects. Here are routines that work for some simple examples I’ve tested. I placed this code in vendor/rails/activerecord/lib/active_record/base.rb within the [...]
Posted in rails | Also tagged , , , , | 5 Comments

Chaining :include’s in Rails to reduce the number of SQL queries

Say you have the following data model and you want to execute a single query that returns all the data at once within the ActiveRecord tables, with the proper rails associations between them. Wouldn’t it be nice if you could do something like A.find(:all, :include => :b => :c => :d => :e) #v1 ? [...]
Posted in programming, rails, scalability | Also tagged , , , , , , | 1 Comment