Python厨とRuby厨が仲直りするスレッドat TECH
Python厨とRuby厨が仲直りするスレッド - 暇つぶし2ch960:デフォルトの名無しさん
07/12/11 16:22:19
>>948
18   #  konata.to_json(:only => [ :id, :name ])
19   #
20   #  {"id": 1, "name": "Konata Izumi"}
-----------------------------------------------------------------------
36   #  konata.to_json(:include => :posts)
37   #
38   #  {"id": 1, "name": "Konata Izumi", "age": 16,
39   #  "created_at": "2006/08/01", "awesome": true,

40   #  "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
41   #        {"id": 2, author_id: 1, "title": "So I was thinking"}]}
-----------------------------------------------------------------------
45   #  konata.to_json(:include => { :posts => {
46   #                  :include => { :comments => { :only => :body } },
48   #                                    :only => :title } })
49   #
50   #  {"id": 1, "name": "Konata Izumi", "age": 16,
51   #  "created_at": "2006/08/01", "awesome": true,

52   #  "posts": [{"comments": [{"body": "1st post!"}, {"body": "Second!"}],
53   #                  "title": "Welcome to the weblog"},
54   #        {"comments": [{"body": "Don't think too hard"}],
55   #                  "title": "So I was thinking"}]}

言うほど悪くはないと思うぞ(サンプルコードとしては)
bodyがどこから出てくるのかいまいちよくわからん…むぅ公式ドキュメント…

URLリンク(caboo.se)



次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch