This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# So, a SELECT DISTINCT on some DBs requires that all order values are in the select clause. | |
# I'm hoping there's a better cross-platform way of doing this without branching, and I | |
# kind of think I must be overlooking something that's already built-in. | |
# Open to suggestions! | |
def distinct_relation(relation) | |
offset, limit = relation.offset_value, relation.limit_value | |
klass.select('DISTINCT subquery.*'). | |
from(Arel::Nodes::As.new( | |
Arel::Nodes::Grouping.new(relation.except(:offset, :limit).arel.ast), | |
Arel.sql('subquery') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
$LOAD_PATH << './lib' | |
require 'arel' | |
def grouping_any(range) | |
literal = Arel.sql('1') | |
literal.eq_any(range.to_a) | |
end | |
def grouping_all(range) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These are nothing fancy. Stick them in your .profile for quick access. | |
# Tail the log of a pow application | |
function powl { | |
tail -f ~/.pow/"$1"/log/development.log | |
} | |
# Restart a pow application | |
function powr { | |
touch ~/.pow/"$1"/tmp/restart.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ godaddy buy wynn.fm | |
-- Reading CC Info from .godaddy... | |
-- THANK YOU FOR PURCHASING YOUR DOMAIN WITH GODADDY! | |
-- WHILE OUR SERVERS THINK ABOUT REGISTERING YOUR DOMAIN | |
-- NAME, PLEASE GIVE CAREFUL CONSIDERATION TO THE | |
-- FOLLOWING SPECIAL OFFERS!!! | |
Would you like to also register the following and SAVE 64%? | |
wynn.net |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Article.joins{person.comments}.where{person.comments.body =~ '%hello%'}.to_sql | |
# => "SELECT \"articles\".* FROM \"articles\" INNER JOIN \"people\" ON \"people\".\"id\" = \"articles\".\"person_id\" INNER JOIN \"comments\" ON \"comments\".\"person_id\" = \"people\".\"id\" WHERE \"comments\".\"body\" LIKE '%hello%'" | |
Person.where{(id + 1) == 2}.first | |
# => #<Person id: 1, parent_id: nil, name: "Aric Smith", salary: 31000> | |
Person.where{(salary - 40000) < 0}.to_sql | |
# => "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"salary\" - 40000 < 0" | |
p = Person.select{[id, name, salary, (salary + 1000).as('salary_after_increase')]}.first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :javascripts do | |
desc 'minify the javascript files residing in app/javascripts to public/javascripts' | |
task :minify do | |
RakeFileUtils.verbose false do | |
Dir["app/javascripts/*.js"].each do |filename| | |
outfile = filename.sub(/^app/, 'public').sub(/\.js$/, '.min.js') | |
puts "#{filename} -> #{outfile}" | |
sh( | |
'java', | |
'-jar', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 1be13d1c88ca518996135e89454c17691afbcc51 Mon Sep 17 00:00:00 2001 | |
From: Ernie Miller <[email protected]> | |
Date: Thu, 6 Jan 2011 20:06:29 -0500 | |
Subject: [PATCH] Fix polymorphic belongs_to associationproxy raising errors when loading target. | |
--- | |
.../belongs_to_polymorphic_association.rb | 5 +++++ | |
.../associations/belongs_to_associations_test.rb | 9 +++++++++ | |
activerecord/test/models/sponsor.rb | 2 ++ | |
3 files changed, 16 insertions(+), 0 deletions(-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 61ad8e150d74f6c2bafeaac73f1b40d11d3092c1 Mon Sep 17 00:00:00 2001 | |
From: Ernie Miller <[email protected]> | |
Date: Thu, 6 Jan 2011 17:13:01 -0500 | |
Subject: [PATCH] Fix polymorphic belongs_to associationproxy raising errors when loading target. | |
--- | |
.../belongs_to_polymorphic_association.rb | 4 ++++ | |
.../associations/belongs_to_associations_test.rb | 9 +++++++++ | |
activerecord/test/models/sponsor.rb | 2 ++ | |
3 files changed, 15 insertions(+), 0 deletions(-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Can this be done with strings? Sure. This feels much nicer to me, though. | |
class Verb < ActiveRecord::Base | |
belongs_to :verbable, :polymorphic => true | |
belongs_to :objectifiable, :polymorphic => true | |
scope :of_interest_to_user, lambda {|u| | |
where( | |
(:objectifiable_type.eq % 'User' & :objectifiable_id.eq % u.id) | | |
(:objectifiable_type.eq % 'Book' & :objectifiable_id.in % u.book_ids) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initialize(base_or_relation, opts = {}) | |
@relation = base_or_relation.scoped | |
@base = @relation.klass | |
@search_key = opts[:search_key] ? opts[:search_key].to_s : 'search' | |
@join_dependency = build_join_dependency | |
@search_attributes = {} | |
@errors = ActiveModel::Errors.new(self) | |
singleton_class.instance_eval "def base; #{@base} end" | |
end |