Skip to content

Commit

Permalink
Fixes for postgresql testing rails#1129, rails#1130, rails#1131
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1199 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Apr 18, 2005
1 parent d547c3f commit 7669011
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
27 changes: 17 additions & 10 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -289,21 +289,28 @@ def self.inherited(child) #:nodoc:
@@default_timezone = :local

class << self # Class methods
# Returns objects for the records responding to either a specific id (1), a list of ids (1, 5, 6) or an array of ids.
# If only one ID is specified, that object is returned directly. If more than one ID is specified, an array is returned.
# Find operates with three different retreval approaches:
#
# * Find by id: This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]).
# If no record can be found for all of the listed ids, then RecordNotFound will be raised.
# * Find first: This will return the first record matched by the options used. These options can either be specific
# conditions or merely an order. If no record can matched, nil is returned.
# # Find all: This will return all the records matched by the options used. If no records are found, an empty array is returned.
#
# All approaches accepts an option hash as their last parameter. The options are:
#
# * <tt>:conditions</tt>:
# * <tt>:order</tt>:
# * <tt>:limit</tt>:
# * <tt>:offset</tt>:
# * <tt>:joins</tt>:
# * <tt>:include</tt>:
#
# Examples:
# Person.find(1) # returns the object for ID = 1
# Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6)
# Person.find([7, 17]) # returns an array for objects with IDs in (7, 17)
# Person.find([1]) # returns an array for objects the object with ID = 1
#
# The last argument may be a Hash of find options. Currently, +conditions+ is the only option, behaving the same as with +find_all+.
# Person.find(1, :conditions => "associate_id = 5"
# Person.find(1, 2, 6, :conditions => "status = 'active'"
# Person.find([7, 17], :conditions => ["sanitize_me = ?", "bare'quote"]
# Person.find(25, :conditions => ["name = :name AND age = :age", { :name => "Mary", :age => 22 }]
#
# +RecordNotFound+ is raised if no record can be found.
def find(*args)
options = extract_options_from_args!(args)

Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/associations_go_eager_test.rb
Expand Up @@ -10,11 +10,11 @@ class EagerAssociationTest < Test::Unit::TestCase
def test_loading_with_one_association
posts = Post.find(:all, :include => :comments)
assert_equal 2, posts.first.comments.size
assert_equal @greetings.body, posts.first.comments.first.body
assert posts.first.comments.include?(@greetings)

post = Post.find(:first, :include => :comments, :conditions => "posts.title = 'Welcome to the weblog'")
assert_equal 2, post.comments.size
assert_equal @greetings.body, post.comments.first.body
assert post.comments.include?(@greetings)
end

def test_loading_with_multiple_associations
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/fixtures/db_definitions/mysql.sql
Expand Up @@ -131,7 +131,7 @@ CREATE TABLE `computers` (

CREATE TABLE `posts` (
`id` INTEGER NOT NULL PRIMARY KEY,
`author_id` INTEGER NOT NULL,
`author_id` INTEGER,
`title` VARCHAR(255) NOT NULL,
`body` TEXT NOT NULL,
`type` VARCHAR(255) NOT NULL
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/fixtures/db_definitions/postgresql.sql
Expand Up @@ -167,7 +167,7 @@ CREATE TABLE authors (
name varchar(255) default NULL
);

CREATE TABLE taske (
CREATE TABLE tasks (
id serial,
starting timestamp,
ending timestamp,
Expand All @@ -181,5 +181,5 @@ CREATE TABLE categories (

CREATE TABLE categories_posts (
category_id integer NOT NULL,
post_id int integer NOT NULL
post_id integer NOT NULL
);
2 changes: 1 addition & 1 deletion activerecord/test/fixtures/db_definitions/sqlite.sql
Expand Up @@ -118,7 +118,7 @@ CREATE TABLE 'computers' (

CREATE TABLE 'posts' (
'id' INTEGER NOT NULL PRIMARY KEY,
'author_id' INTEGER NOT NULL,
'author_id' INTEGER,
'title' VARCHAR(255) NOT NULL,
'type' VARCHAR(255) NOT NULL,
'body' TEXT NOT NULL
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/fixtures/posts.yml
Expand Up @@ -14,7 +14,6 @@ thinking:

authorless:
id: 3
author_id: ""
title: I don't have any comments
body: I just don't want to
type: Post

0 comments on commit 7669011

Please sign in to comment.