4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/railz_lite/models/associatable2.rb', line 4
def has_one_through(name, through_name, source_name)
define_method(name) do
through_options = self.class.assoc_options[through_name]
source_options =
through_options.model_class.assoc_options[source_name]
through_table = through_options.table_name
through_pk = through_options.primary_key
through_fk = through_options.foreign_key
source_table = source_options.table_name
source_pk = source_options.primary_key
source_fk = source_options.foreign_key
key_val = self.send(through_fk)
results = DBConnection.execute(" SELECT\n \#{source_table}.*\n FROM\n \#{through_table}\n JOIN\n \#{source_table}\n ON\n \#{through_table}.\#{source_fk} = \#{source_table}.\#{source_pk}\n WHERE\n \#{through_table}.\#{through_pk} = ?\n SQL\n\n source_options.model_class.parse_all(results).first\n end\nend\n", key_val)
|