zendesk/zombie_record — pull request #4 by vkmita (2014-05-09 19:28:35+00:00)
Title: [WIP] When a record is deleted it should use unscoped association calls

@libo @dasch

I think this addition is useful, for example, you can retrieve a deleted category, and gracefully get the default_translation without having to do something like this:

```
>> DC::Content.with_deleted { DC::Translation.with_deleted { category.default_translation.title } }
DC::Content Load (0.2ms) SELECT `dc_contents`.* FROM `dc_contents` WHERE `dc_contents`.`source_id` = 10017 AND `dc_contents`.`source_type` = 'Category' LIMIT 1
DC::Translation Load (0.3ms) SELECT `dc_translations`.* FROM `dc_translations` WHERE `dc_translations`.`id` = 10112 LIMIT 1
=> "Using Help Center"
```
Instead we can simply do:

```
>> category.default_translation.title
DC::Content Load (0.2ms) SELECT `dc_contents`.* FROM `dc_contents` WHERE `dc_contents`.`source_id` = 10017 AND `dc_contents`.`source_type` = 'Category' LIMIT 1
DC::Translation Load (0.3ms) SELECT `dc_translations`.* FROM `dc_translations` WHERE `dc_translations`.`id` = 10112 LIMIT 1
=> "Using Help Center"
```

The thing I'm having trouble with is the timing of redefining the association methods. If I do a class_eval at the time the module is included it doesn't work because it seems like Rails is redefining the has_many associations after I initially redefine them. The only solution I came up with for that was overriding the methods in an after_initialize callback, and simply marking which classes were overridden so we don't do it twice.

What do you guys think?