Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:57:31+00:00 2026-05-23T16:57:31+00:00

My application has the following model classes: class Parent < ActiveRecord::Base # Setup accessible

  • 0

My application has the following model classes:

class Parent < ActiveRecord::Base
    # Setup accessible (or protected) attributes for your model
    attr_accessible :child_attributes, :child

    has_one :child

    accepts_nested_attributes_for :child

    #This is to generate a full JSON graph when serializing
    def as_json(options = {})
        super(options.merge, :include => {:child => {:include => :grandchild } })
    end
end

class Child < ActiveRecord::Base
    # Setup accessible (or protected) attributes for your model
    attr_accessible :grandchild_attributes, :grandchild

    belongs_to :parent
    has_one :grandchild

    accepts_nested_attributes_for :grandchild
end

class Grandchild < ActiveRecord::Base
    belongs_to :child
end

The, in my controller i have a create method, defined as follows:

def create
    @parent = Parent.new(params[:parent])
    #Rest ommited for brevity - just respond_with and save code
    end
end

My request is showing up in the logs as:

Parameters: {"parent"=>{"child"=>{"grandchild"=>{"gc_attr1"=>"value1", "gc_attr2"=>"value2"}}, "p_attr1"=>"value1"}

Which is the full serialization graph that came from my iphone app client that uses RestKit.
I have seen on other SO questions like here , thats refers to this blog post.
My problem, however is that I don’t know how to control the serialized graph from my client side using RestKit in order to build a request like this (and that way, it works.. tested with debugger)

Parameters: {"parent"=>{"child_attributes"=>{"grandchild_attributes"=>{"gc_attr1"=>"value1", "gc_attr2"=>"value2"}}, "p_attr1"=>"value1"}

Anyone have ideas if there is any option I can pass on to the Parent.new method or customize the RestKit JSON output in a way that I may achieve the model_attributes structure within nested JSON objects?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:57:32+00:00Added an answer on May 23, 2026 at 4:57 pm

    I have solved this issue by using RABL, which is a gem to render json as views. Awesome work.
    This allowed me to customize the serialization graph of my model.

    On RestKit side (using OM2.0 – new object mapping), I have changed my mappings all to child_attributes for all relationships, for instance:

    RKObjectMapping* parentMapping = ... //Initialize your mapping here
    RKObjectMapping* childMapping  = ... //Initialize your mapping here
    
    //Configure mapping relationship with child
    [parentMapping  mapKeyPath:@"child_attributes" toRelationship:@"childProperty" withObjectMapping:childMapping];
    
    //Register mappings
    RKObjectManager* manager = [RKObjectManager sharedManager];
    [manager.mappingProvider registerMapping:parentMapping withRootKeyPath:@"parent"];
    [manager.mappingProvider registerMapping:childMapping withRootKeyPath:@"child"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application has an Entity Framework model containing a many-to-many relationship like the following:
My android application has several warnings of the following form when I run it
I'm building WPF client application. I'm following MVC pattern. The project solution has many
My application has a plug-in model that allows third-party developers to write assemblies that
I have an MVC 2 application that has the following on it; <% using(
I have an application which has the following characteristics There are Clubs Each Club
I have an application architecture which has following layers (or c# projects). web front
I have a a view that has the following code: <h2><%= Model.Company.CompanyName %></h2> <h3>Projects</h3>
Application has an auxiliary thread. This thread is not meant to run all the
My application has a need to let the user choose a date from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.