Permalink
Browse files

Moved primary_key to relation, send pk to engine, to build a better

query if possible.
  • Loading branch information...
1 parent f37c4a4 commit 1c0d7dc7f62e8744b476464f8aefc1867986f0bd @miloops miloops committed Feb 18, 2010
@@ -20,7 +20,7 @@ def method_missing(method, *args, &block)
module CRUD
def create(relation)
- connection.insert(relation.to_sql)
+ connection.insert(relation.to_sql, nil, relation.primary_key)
end
def read(relation)
@@ -22,13 +22,8 @@ def select_sql
end
def limited_update_conditions(conditions)
- begin
- quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key)
- rescue NameError
- quote_primary_key = engine.quote_column_name("id")
- end
-
- "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})"
+ quoted_primary_key = engine.quote_table_name(primary_key)
+ "WHERE #{quoted_primary_key} IN (SELECT #{quoted_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})"
end
protected
@@ -20,5 +20,13 @@ def christener
def inclusion_predicate_sql
"IN"
end
+
+ def primary_key
+ @primary_key ||= begin
+ table.name.classify.constantize.primary_key
+ rescue NameError
+ "id"
+ end
+ end
end
end

0 comments on commit 1c0d7dc

Please sign in to comment.