Here's the story: I'm trying to tie Deal and Task together with has_many association but the problem is that they relate only through field in third table TasksTask where Deal's id hidden in serialized php array, so i can get such value based on Deal's id like that:
PHP.serialize["D_#{Deal.instance.id}"]
though Task and TasksTask relate with each other through foreign key, which is fine and simple integer
For now I grab tasks with custom method with Task.where(blabla), but since I don't have an association I can't use it in 'includes' method for batch fetching, and i got a lot of flying requests, and it is sad.
I've already tried finder_sql param, tried lambdas and procs but they don't work for some reasons for me (if i pass it to 'conditions' it ends up with 'where ... AND [lambda condition] ' while trying to use deal_id as foreign key which I don't have for Deals) And I was also thinking to fake that strange field as an attribute on Deal with:
attr_accessor :STRANGE_FIELD_NAME
def after_initialize
@STRANGE_FIELD = PHP.serialize["D_#{self.id}"]
end
and also tried metaprogramming magic but ActiveRecord already use it a lot, and simple respond_to and method_missing didn't helped at all, except giving me this crazy value when I call as accessor method on Deal's instance.
I'm doing all this weird stuff cuz trying to build a system on top of another, that doesn't have normal api, but used a lot and it seems unavoidable for now. Which is also sad.
So the question is can I fake it somehow or I need to create fourth table with normal foreign key for Deals and sync it somehow(cron if it would be OK for my boss or sql triggers )
Any advice would be appreciated. :-)