diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fac479dae..99741cdf3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -275,7 +275,7 @@ class ApplicationController < ActionController::Base end end def model_create_render_item (generic_object) - render :json => generic_object, :status => :created + render :json => generic_object.attributes_with_associations, :status => :created end def model_update_render (object, params) @@ -298,7 +298,7 @@ class ApplicationController < ActionController::Base end end def model_update_render_item (generic_object) - render :json => generic_object, :status => :ok + render :json => generic_object.attributes_with_associations, :status => :ok end def model_destory_render (object, params) @@ -327,13 +327,13 @@ class ApplicationController < ActionController::Base end end def model_show_render_item (generic_object) - render :json => generic_object, :status => :ok + render :json => generic_object.attributes_with_associations, :status => :ok end def model_index_render (object, params) begin - generic_object = object.all - model_index_render_result( generic_object ) + generic_objects = object.all + model_index_render_result( generic_objects ) rescue Exception => e logger.error e.message logger.error e.backtrace.inspect diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 81f035f8d..447faf05e 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -83,7 +83,8 @@ returns set rellations of model based on params - result = Model.param_set_associations(params) + model = Model.find(1) + result = model.param_set_associations(params) returns @@ -112,6 +113,32 @@ returns =begin +get rellations of model based on params + + model = Model.find(1) + attributes = model.attributes_with_associations + +returns + + hash with attributes and association ids + +=end + + def attributes_with_associations + + # set relations + attributes = self.attributes + self.class.reflect_on_all_associations.map { |assoc| + real_key = assoc.name.to_s[0,assoc.name.to_s.length-1] + '_ids' + if self.respond_to?( real_key ) + attributes[ real_key ] = self.send( real_key ) + end + } + attributes + end + +=begin + remove all not used params of object (per default :updated_at, :created_at, :updated_by_id and :created_by_id) result = Model.param_validation(params)