{"comment":{"created_at":"2011-10-16T11:00:22Z","body":"> Can you paste in you mapping for the paper class and any other\r\naffected classes to take a look at so I could have a better picture?\r\nAlso, are you using rubyamf_config.rb or are you using in model\r\nmapping?\r\n\r\n```ruby\r\nclass Division < ActiveRecord::Base\r\n  attr_accessible :name\r\n\r\n  # RubyAMF in-class mapping\r\n  as_class 'Division'\r\n\r\n  has_many :papers, :dependent => :destroy\r\n  validates :name, :presence => true\r\nend\r\n```\r\n\r\n```ruby\r\nclass Paper < ActiveRecord::Base\r\n  # RubyAMF in-class mapping\r\n  as_class 'Paper'\r\n\r\n  belongs_to :division\r\nend\r\n```\r\n\r\nI think there was a very important point about which I was slightly ambiguous in my initial post.\r\n\r\nWhen I said this:\r\n\r\n> This model object will NOT necessarily have ALL its properties and associations set. Using the previous rubyamf_plugin, when such a model object is received by my Rails action, only those properties and associations which the Flex object had, would be set on the deserialized Rails object.\r\n\r\nI did not mean to convey that some properties and associations did not exist on the model object at all (by using the [Transient] metatag). What I meant to say is: the properties and association are set to nil on the Flex object when sent from Flex. I guess this answers Stephen's questions.\r\n\r\nSo, the problem is (as Stephen rightly guessed) that when an association is set to nil on an incoming Flex object, the deserializer still tries to set the association. And this fails inside ActiveRecord (as shown by the backtrace).\r\n\r\n\r\n> Can you confirm for me that the property you're receiving in Rails is set to nil?\r\n\r\nYes, since the associations are not set on the Flex side at all, they are detected as nil on the Rails side.\r\n\r\n> If it is nil, then I'll add a check just for associations to skip them if they are nil. If someone wants to unset them, they'll have to send it back as an empty array then.\r\n\r\nPerfect. That will do, I think.\r\n\r\nThanks.","updated_at":"2011-10-16T11:00:22Z","url":"https://api.github.com/repos/rubyamf/rubyamf/issues/comments/2420362","id":2420362,"user":{"gravatar_id":"ca6208c0ab0061ded967ce0d4afa5e71","avatar_url":"https://secure.gravatar.com/avatar/ca6208c0ab0061ded967ce0d4afa5e71?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/t-anjan","id":743179,"login":"t-anjan"}},"action":"created","issue":{"number":3,"created_at":"2011-10-15T17:23:39Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"In my project, the parameters of my AMF calls from Flex are not always just integers or strings. The demo app only shows parameters of integer type. I send model objects as parameters too (for example a \"blog\" object). This model object will NOT necessarily have ALL its properties and associations set. Using the previous rubyamf_plugin, when such a model object is received by my Rails action, only those properties and associations which the Flex object had, would be set on the deserialized Rails object. Then, I read the required (relevant) properties and / or associations and saved them to the DB.\r\n\r\nIn RubyAMFv2, this does not seem to work. RubyAMFv2 seems to expect to find ALL parameters and associations on every Flex object it receives. When it doesn't find one, it throws an exception. I think this is undesirable behavior.\r\n\r\nI think the problem is near here: line 67 - 70 in the [lib/rubyamf/rails/model.rb](https://github.com/rubyamf/rubyamf/blob/master/lib/rubyamf/rails/model.rb#L67):\r\n\r\n    # Set attributtes\r\n    # warhammerkid: Should we be setting associations some other way (not attributes)?\r\n    rubyamf_set_non_attributes attrs, base_attrs\r\n    self.send(:attributes=, attrs)\r\n\r\nThe first 11 lines of the backtrace of the error is below. \"papers\" is an association that I am NOT sending from Flex.\r\n\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/gems/activerecord-3.0.10/lib/active_record/associations/association_collection.rb:354:in `replace'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/gems/activerecord-3.0.10/lib/active_record/associations.rb:1515:in `papers='\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:120:in `send'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:120:in `rubyamf_set_non_attributes'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:116:in `each'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:116:in `rubyamf_set_non_attributes'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/rails/model.rb:69:in `rubyamf_init'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/class_mapping.rb:201:in `populate_ruby_obj'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:42:in `populate_from_stream'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:42:in `handle_amf'\",\r\n    \"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:29:in `call'\"\r\n\r\nPlease let me know if you need any other information. I would appreciate any assistance to solve this problem.\r\n\r\nThanks.\r\nAnjan","comments":4,"title":"Tries to set associations which are not sent from Flex","updated_at":"2011-10-16T11:00:22Z","url":"https://api.github.com/repos/rubyamf/rubyamf/issues/3","id":1918267,"assignee":null,"milestone":null,"closed_at":null,"user":{"gravatar_id":"620b47b555091f6ba7d35a30a58cc725","avatar_url":"https://secure.gravatar.com/avatar/620b47b555091f6ba7d35a30a58cc725?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/warhammerkid","id":26395,"login":"warhammerkid"},"html_url":"https://github.com/rubyamf/rubyamf/issues/3","labels":[],"state":"open"},"legacy":{"issue_id":1918267,"comment_id":2420362}}