public
Rubygem
Description: A generator of Lexical Database Applications from a compliant Lexical Markup Framwork schema
Homepage: http://coldic.sourceforge.net
Clone URL: git://github.com/spejman/coldic.git
 * Ensure that the joins conditions have all the table declarations
declared before.
 * Add try libraries for safe nulls.
spejman (author)
Wed Jun 25 04:28:38 -0700 2008
commit  36f21d2ace3533718839716e6d85d3a0d70777c0
tree    244a1438b59ff8c4a392ae79b887b3935aad74bf
parent  f38e6f6a60608573efde9227bdc70ac9960f0146
...
57
58
59
 
 
60
61
62
...
57
58
59
60
61
62
63
64
0
@@ -57,6 +57,8 @@ end
0
 # Mime::Type.register "text/richtext", :rtf
0
 # Mime::Type.register "application/x-mobile", :mobile
0
 
0
+require "try"
0
+
0
 # File used to include the inflections not solved by the RoR inflector
0
 META_RAILS_INFLECTIONS_FILE = File.join("#{RAILS_ROOT}/config","metarails_inflections.rb")
0
 require META_RAILS_INFLECTIONS_FILE if File.exists? META_RAILS_INFLECTIONS_FILE
...
173
174
175
176
 
177
178
179
180
 
 
181
182
183
...
266
267
268
269
270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
272
273
...
173
174
175
 
176
177
178
 
 
179
180
181
182
183
...
266
267
268
 
 
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
0
@@ -173,11 +173,11 @@ module MetaQuery
0
       st.from[from_tables]
0
       
0
       joins = all_joins_sql#.sort_by {|j| j[1].to_s.size} # order by key size bigger key --> deeper in the query ...
0
-# raise all_joins_sql.to_json
0
+ # raise all_joins_sql.to_json
0
       joins.each do |join_def|
0
         st.left_join[join_def[1]]
0
- # st.send(:"#{join_def[0].gsub(" ", "_")}")[join_def[1]]
0
- # raise join_def[2]
0
+ # st.send(:"#{join_def[0].gsub(" ", "_")}")[join_def[1]]
0
+ # raise join_def[2]
0
         st.on { eval join_def[2] }
0
       end
0
       
0
@@ -266,8 +266,21 @@ module MetaQuery
0
             joins << [join_type, join_table, join_condition]
0
           end
0
         end
0
- end
0
- joins
0
+ end
0
+
0
+ # Order joins. Objective: Declare the tables before using them in join conditions.
0
+ joins = joins.sort_by do |join|
0
+ j_tables_declaration = joins.collect {|j| j[1].to_s.split(" ")[-1]}.flatten
0
+ idx = joins.index join
0
+ # Take the farthest table declaration position of each tables in the
0
+ # join condition. Move all the correct positions before (idx - joins.size),
0
+ # and the tables that need a table that is declared before, put them in the
0
+ # old table definition position.
0
+ far_table_condition_position = join[2].scan(/(\w+_\w+)\./).flatten.collect do |join_cond_table|
0
+ j_tables_declaration.index(join_cond_table) if j_tables_declaration[idx+1..-1].include?(join_cond_table)
0
+ end.compact.max || (idx - joins.size)
0
+ # FIXME: (--> needs) [a --> b], [b --> c], [c --> c] (think if is a possible situation)
0
+ end
0
     end
0
     
0
     def all_sql_conditions

Comments

    No one has commented yet.