Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #2231 (closed enhancement: wontfix)

Opened 4 years ago

Last modified 2 years ago

Support :finder_sql option for has_one statement.

Reported by: yannick@koehler.name Assigned to: David
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: has_one finder_sql active record
Cc:

Description

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'.

Change History

01/21/07 08:11:21 changed by jarkko

  • version changed from 0.13.1 to edge.
  • type changed from defect to enhancement.
  • milestone set to 1.x.

05/29/07 05:22:46 changed by josh

  • status changed from new to closed.
  • resolution set to wontfix.

Closing because there is no proposed patch.