Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping ActiveRecords to non-AR ruby objects => SystemStackError #20

Open
findchris opened this issue Feb 11, 2010 · 1 comment
Open

Comments

@findchris
Copy link
Contributor

Hi there.

I have two (Rails) applications: One is using ActiveRecord, the other is not.

In the DB-backed app I have models like:

class Post < ActiveRecord::Base
  has_many :comments

  include ROXML
  xml_attr :id
  xml_attr :body
  xml_attr :comments, :as => [Comment], :in => "comments"
end

class Comment < ActiveRecord::Base
  belongs_to :post

  include ROXML
  xml_attr :id
  xml_attr :body
  xml_attr :post, :as => Post
end 

In the non-AR-based app, which will consume the XML generated from the AR-based app, I have:

class Post
  include ROXML

  xml_accessor :id
  xml_accessor :body
  xml_accessor :comments, :as => [Comment]
end
class Comment
  include ROXML

  xml_accessor :id
  xml_accessor :body
  xml_accessor :post, :as => Post
end

The problem is, when I try to generate the XML, I (not so unexpectedly) get this:

>> Post.first.to_xml.to_s
SystemStackError: stack level too deep

So the question is: How to map ActiveRecord objects (with associations) to non-ActiveRecord objects using ROXML?

In the app not using ActiveRecord, I'd like to be able to go through relations, such as in:

the_post.comments.post.name

Not sure if this is possible, but I'd appreciate your insight.

Cheers.
-Chris

@findchris
Copy link
Contributor Author

Forget the SystemStackError: The circular reference is probably not the way to go.

However, another question: ROXML overrides ActiveRecord's to_xml method and I was wondering if there was a way to get the XML that would be generated by ActiveRecord's to_xml() instead of ROXML's to_xml()?

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant