Skip to content

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

@findchris

Description

@findchris

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions