I'm trying to store the current versions of a nested association so I can roll back over time, and I can't figure out what's wrong here. Here's my setter and getter:
def serialize_children
self.children = ActiveSupport::Base64.encode64(Marshal.dump(self.ads))
end
def unserialize_children
Marshal.load(ActiveSupport::Base64.decode64(self.children))
end
This appears to properly encode the data:
c = Composition.find(39)
=> #<Composition id: 39, name: "help me", campaign_id: 5, created_at: "2011-01-10 03:49:08", updated_at: "2011-01-10 16:34:09", position: 1, children: "", revisable_original_id: nil, revisable_branched_from_id: nil, revisable_number: 5, revisable_name: nil, revisable_type: nil, revisable_current_at: nil, revisable_revised_at: "2011-01-10 04:14:46", revisable_deleted_at: nil, revisable_is_current: true>
c.serialize_children
=> "BAhvOjNBY3RpdmVSZWNvcmQ6OkFzc29jaWF0aW9uczo6SGFzTWFueUFzc29j\naWF0aW9uCzoRQGNvdW50ZXJfc3FsIh4iYWRzIi5jb21wb3NpdGlvbl9pZCA9\nIDM5OhBAZmluZGVyX3NxbEAGOhBAcmVmbGVjdGlvbm86NEFjdGl2ZVJlY29y\nZDo6UmVmbGVjdGlvbjo6QXNzb2NpYXRpb25SZWZsZWN0aW9uDjoQQGNsYXNz\nX25hbWUiB0FkOg1Ab3B0aW9uc3sJOg5kZXBlbmRlbnQ6DGRlc3Ryb3k6DWF1\ndG9zYXZlVDoLZXh0ZW5kWwA6Cm9yZGVyIhFwb3NpdGlvbiBBU0M6FkBwcmlt\nYXJ5X2tleV9uYW1lIhNjb21wb3NpdGlvbl9pZDoLQGtsYXNzYwdBZDoKQG5h\nbWU6CGFkczoQQGNvbGxlY3Rpb25UOhdAcXVvdGVkX3RhYmxlX25hbWUiCiJh\nZHMiOgtAbWFjcm86DWhhc19tYW55OhNAYWN0aXZlX3JlY29yZGMQQ29tcG9z\naXRpb246C0Bvd25lcm86EENvbXBvc2l0aW9uCDoWQGF0dHJpYnV0ZXNfY2Fj\naGV7ADoJQGFkc0AAOhBAYXR0cmlidXRlc3sVIgluYW1lIgxoZWxwIG1lIg1w\nb3NpdGlvbmkGIg9jcmVhdGVkX2F0IhgyMDExLTAxLTEwIDAzOjQ5OjA4IhNy\nZXZpc2FibGVfdHlwZTAiEGNhbXBhaWduX2lkaQoiD3VwZGF0ZWRfYXQiGDIw\nMTEtMDEtMTAgMTY6MzQ6MDkiH3JldmlzYWJsZV9icmFuY2hlZF9mcm9tX2lk\nMCIVcmV2aXNhYmxlX251bWJlcmkKIgdpZGksIhNyZXZpc2FibGVfbmFtZTAi\nGnJldmlzYWJsZV9vcmlnaW5hbF9pZDAiGXJldmlzYWJsZV9kZWxldGVkX2F0\nMCIZcmV2aXNhYmxlX2N1cnJlbnRfYXQwIhlyZXZpc2FibGVfaXNfY3VycmVu\ndCIGdCINY2hpbGRyZW4iACIZcmV2aXNhYmxlX3JldmlzZWRfYXQiGDIwMTEt\nMDEtMTAgMDQ6MTQ6NDY6DEBsb2FkZWRUOgxAdGFyZ2V0WwA=\n"
But no matter what I try to unserialize it, I always get an empty array as the result. Is this because of the association overriding my attempt to set a new array at the same name? I don't get any errors, but I don't get any data either.
Thanks in advance,
Walter
But no matter what I try to unserialize it, I always get an empty array as the result. Is this because of the association overriding my attempt to set a new array at the same name? I don't get any errors, but I don't get any data either.
Is there also an association named children ?
Fred
But no matter what I try to unserialize it, I always get an empty array as the result. Is this because of the association overriding my attempt to set a new array at the same name? I don't get any errors, but I don't get any data either.
Is there also an association named children ?
No, children is just a text column on Composition, and Ad doesn't have anything like it. I've tried the following in console: (paraphrasing because I'm not at my computer)
c = Composition.find 39
[big hash of object data]
c.children
"" (empty string)
c.serialize_children
(big base64 string)
c.children
(same big.base64 string)
c.unserialize_children
(empty array)
Walter
But no matter what I try to unserialize it, I always get an empty array as the result. Is this because of the association overriding my attempt to set a new array at the same name? I don't get any errors, but I don't get any data either.
Is there also an association named children ?
No, children is just a text column on Composition, and Ad doesn't have anything like it. I've tried the following in console: (paraphrasing because I'm not at my computer)
Does it make any difference if you dump self.ads.to_a instead of self.ads?
Fred
>>> But no matter what I try to unserialize it, I always get an empty array as the result. Is this because of the association overriding my attempt to set a new array at the same name? I don't get any errors, but I don't get any data either.
>> Is there also an association named children ?
> No, children is just a text column on Composition, and Ad doesn't have anything like it. I've tried the following in console: (paraphrasing because I'm not at my computer)
Does it make any difference if you dump self.ads.to_a instead of self.ads?
Fred
Then I get what looks like an empty array in base64 on the input, and
on the output.
Walter
> > No, children is just a text column on Composition, and Ad doesn't have anything like it. I've tried the following in console: (paraphrasing because I'm not at my computer)
> Does it make any difference if you dump self.ads.to_a instead of self.ads?
> Fred
Then I get what looks like an empty array in base64 on the input, and
on the output.
What does the non base64 encoded, dumped version of self.ads look
like. What is the value of self.ads ?
Fred
> Then I get what looks like an empty array in base64 on the input, and
> on the output.
What does the non base64 encoded, dumped version of self.ads look
like. What is the value of self.ads ?
Fred
Head -> Table
Composition 39 didn't have any children at the time I serialized it.
So I got back exactly what I should have. Trying this code again with
a different record I get back exactly what I put into it. Thanks for
your help.
Walter