0

For arguments sake, lets say I have legs as my object. I'm trying to call as_json on it and include all associations - which are set up correctly as it works perfectly in the console.

This is what I have:

@legs.as_json(
  :include => {
    :shoes => {
      :include => {
        :left_shoe => {
          :include => {
            :shoe_lace => {:include => :sock}
          }
        }
      },
      :right_shoe => {
        :include => {
          :shoe_lace => {:include => :sock}
        }
      }
    }
  }
)

For some reason it's not including right_shoe. It just stops at left_shoe. Any ideas?

4

2 回答 2

1

我认为根据评论,您的右鞋处于错误的水平。尝试这个:

@legs.as_json(
  :include => {
    :shoes => {
      :include => {
        :left_shoe => {
          :include => {
            :shoe_lace => {:include => :sock}
          }
        },
        :right_shoe => {
          :include => {
            :shoe_lace => {:include => :sock}
          }
        }
      }
    }
  }
)
于 2013-05-09T17:10:20.043 回答
0

Have you ever try this gem, this is pretty cool to manipulate JSON model association:

https://github.com/fabrik42/acts_as_api

于 2013-05-10T21:01:35.773 回答