Path: | doc/release_notes/4.2.0.txt |
Last Update: | Sat Jun 02 02:04:22 +0000 2018 |
DB.from(:a, DB[:b].where(:c=>:a__d).lateral) # SELECT * FROM a, # LATERAL (SELECT * FROM b WHERE (c = a.d)) AS t1
You can use a similar syntax when joining tables:
DB[:a].cross_join(DB[:b].where(:c=>:a__d).lateral) # SELECT * FROM a # CROSS JOIN LATERAL (SELECT * FROM b WHERE (c = a.d)) AS t1
If you are using Microsoft SQL Server, you can use the new mssql_emulate_lateral_with_apply extension to emulate LATERAL subqueries via CROSS/OUTER APPLY.
This works by defining triggers on the underlying model tables that use NOTIFY, and spinning up a thread in your application processes that uses LISTEN, and refreshes the cache for the related model whenever it receives a notification that the underlying table has been modified.
This extension should make it possible to use the static_cache plugin with the :frozen=>false option for any table that is small and not frequently updated.
DB.from{table_returning_function(arg1, arg2)}
DB.loose_count(:table)
Note that you still need to be careful if you mutate objects:
m = Model.new(:a=>'a') m2 = m.dup m.a.gsub!('a', 'b') # also changes m2