I have the following schema:
Node {
int id
int node_type
User user
date created_on
};
datatype1 {
int id
data ...
}
datatype2 {
int id
Node node_of_type_datatype1
data ...
}
node_type is a string reprensenting the name of a model the node is assocaited with. I can't know in advance which type will exists because I intend to have customer related dynamic model and I intent to have those model map to a db table directly for speed. The two datatypes are example of such dynamic model where one has a relation with the other, yet that relation has to use the Node model because I have a revision system that require so (the datatype1/2 models only store "current" revision entry and contains no entry when the node has been deleted at the top of trunk).
So anyway, I would like to be able to says something like:
class Datatype2 ...
has_one :datatype1,
:class_name => 'datatype1',
:foreign_key => 'node_of_type_datatype1',
:finder_sql => "select dt1.* from nodes n, revisions r, datatype1 dt1 where n.id = :id and dt1.revision_id = r.id and r.node_id = n.id"
}
This is basically the same thing as :finder_sql for has_many with the exception of the sql query having 1 parameter :id for inserting there the value of the actual datatype2 model foreign_key field 'node_of_type_datatype1'.