maged
maged

Reputation: 889

Change naming schema of first level associations in to_xml (ActiveRecord::Serialization)

ActiveRecord's to_xml serialization lets you include first level assocations (with :include), as well as change the naming convention (by :dasherize or :camelize). Putting the two together looks like this:

  firm.to_xml :dasherize => false, include: :account

This only changes the naming convention on firm's fields, and not account's. I've tried the following, which throws back syntax errors:

  firm.to_xml :dasherize => false, include: :account {:dasherize => false}
  firm.to_xml :dasherize => false, include: {:account {:dasherize => false}}

Upvotes: 0

Views: 35

Answers (2)

Ruy Rocha
Ruy Rocha

Reputation: 894

If you're using Ruby 1.9.x or above:

firm.to_xml dasherize: false, include: { account: { dasherize: false } }

Upvotes: 1

maged
maged

Reputation: 889

The correct syntax is

  firm.to_xml :dasherize => false, include: {:account => {:dasherize => false}}

Upvotes: 0

Related Questions