Changeset 8113
- Timestamp:
- 11/08/07 03:37:16 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (10 diffs)
- trunk/activerecord/lib/active_record/base.rb (modified) (23 diffs)
- trunk/activerecord/lib/active_record/calculations.rb (modified) (7 diffs)
- trunk/activerecord/lib/active_record/callbacks.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb (modified) (7 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/fixtures.rb (modified) (7 diffs)
- trunk/activerecord/lib/active_record/migration.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/reflection.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/serializers/xml_serializer.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/timestamp.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/transactions.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/validations.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8107 r8113 1 1 *SVN* 2 3 * Smattering of grammatical fixes to documentation. Closes #10083 [BobSilva] 2 4 3 5 * Enhance explanation with more examples for attr_accessible macro. Closes #8095 [fearoffish, Marcel Molina] trunk/activerecord/lib/active_record/associations.rb
r8109 r8113 244 244 # == Unsaved objects and associations 245 245 # 246 # You can manipulate objects and associations before they are saved to the database, but there is some special behavio ur you should be246 # You can manipulate objects and associations before they are saved to the database, but there is some special behavior you should be 247 247 # aware of, mostly involving the saving of associated objects. 248 248 # … … 268 268 # 269 269 # Similiar to the normal callbacks that hook into the lifecycle of an Active Record object, you can also define callbacks that get 270 # trigge d when you add an object to or remove an object from an association collection. Example:270 # triggered when you add an object to or remove an object from an association collection. Example: 271 271 # 272 272 # class Project … … 585 585 # * <tt>collection=objects</tt> - replaces the collections content by deleting and adding objects as appropriate. 586 586 # * <tt>collection_singular_ids</tt> - returns an array of the associated objects' ids 587 # * <tt>collection_singular_ids=ids</tt> - replace the collection bythe objects identified by the primary keys in +ids+587 # * <tt>collection_singular_ids=ids</tt> - replace the collection with the objects identified by the primary keys in +ids+ 588 588 # * <tt>collection.clear</tt> - removes every object from the collection. This destroys the associated objects if they 589 589 # are associated with <tt>:dependent => :destroy</tt>, deletes them directly from the database if <tt>:dependent => :delete_all</tt>, 590 # o r otherwise sets their foreign keys to NULL.590 # otherwise sets their foreign keys to NULL. 591 591 # * <tt>collection.empty?</tt> - returns +true+ if there are no associated objects. 592 592 # * <tt>collection.size</tt> - returns the number of associated objects. … … 622 622 # * <tt>:order</tt> - specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment, 623 623 # such as <tt>last_name, first_name DESC</tt> 624 # * <tt>:group</tt> - specify the attribute by which the associated objects are returned as a <tt>GROUP BY</tt> SQL fragment,625 # such as +category+626 624 # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name 627 625 # of this class in lower-case and +_id+ suffixed. So a +Person+ class that makes a +has_many+ association will use +person_id+ … … 634 632 # associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added. 635 633 # * <tt>:counter_sql</tt> - specify a complete SQL statement to fetch the size of the association. If <tt>:finder_sql</tt> is 636 # specified but <tt>:counter_sql</tt>, <tt>:counter_sql</tt> will be generated by replacing <tt>SELECT ... FROM</tt> with <tt>SELECT COUNT(*) FROM</tt>.634 # specified but not <tt>:counter_sql</tt>, <tt>:counter_sql</tt> will be generated by replacing <tt>SELECT ... FROM</tt> with <tt>SELECT COUNT(*) FROM</tt>. 637 635 # * <tt>:extend</tt> - specify a named module for extending the proxy. See "Association extensions". 638 636 # * <tt>:include</tt> - specify second-order associations that should be eager loaded when the collection is loaded. … … 640 638 # * <tt>:limit</tt>: An integer determining the limit on the number of rows that should be returned. 641 639 # * <tt>:offset</tt>: An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows. 642 # * <tt>:select</tt>: By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if you for example want to do a join,640 # * <tt>:select</tt>: By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if you, for example, want to do a join 643 641 # but not include the joined columns. 644 642 # * <tt>:as</tt>: Specifies a polymorphic interface (See <tt>#belongs_to</tt>). … … 709 707 # * <tt>:conditions</tt> - specify the conditions that the associated object must meet in order to be included as a +WHERE+ 710 708 # SQL fragment, such as <tt>rank = 5</tt>. 711 # * <tt>:order</tt> - specify the order from which the associated object will be picked at the top. Specified as712 # an <tt>ORDER BY</tt> SQL fragment,such as <tt>last_name, first_name DESC</tt>709 # * <tt>:order</tt> - specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment, 710 # such as <tt>last_name, first_name DESC</tt> 713 711 # * <tt>:dependent</tt> - if set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to 714 712 # <tt>:delete</tt>, the associated object is deleted *without* calling its destroy method. If set to <tt>:nullify</tt>, the associated … … 722 720 # Option examples: 723 721 # has_one :credit_card, :dependent => :destroy # destroys the associated credit card 724 # has_one :credit_card, :dependent => :nullify # updates the associated records foreign key value to nullrather than destroying it722 # has_one :credit_card, :dependent => :nullify # updates the associated records foreign key value to NULL rather than destroying it 725 723 # has_one :last_comment, :class_name => "Comment", :order => "posted_on" 726 724 # has_one :project_manager, :class_name => "Person", :conditions => "role = 'project_manager'" … … 772 770 # * <tt>:conditions</tt> - specify the conditions that the associated object must meet in order to be included as a +WHERE+ 773 771 # SQL fragment, such as <tt>authorized = 1</tt>. 774 # * <tt>:order</tt> - specify the order from which the associated object will be picked at the top. Specified as775 # an <tt>ORDER BY</tt> SQL fragment,such as <tt>last_name, first_name DESC</tt>772 # * <tt>:order</tt> - specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment, 773 # such as <tt>last_name, first_name DESC</tt> 776 774 # * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name 777 775 # of the associated class in lower-case and +_id+ suffixed. So a +Person+ class that makes a +belongs_to+ association to a 778 776 # +Boss+ class will use +boss_id+ as the default +foreign_key+. 779 # * <tt>:counter_cache</tt> - caches the number of belonging objects on the associate class through use of +increment_counter+777 # * <tt>:counter_cache</tt> - caches the number of belonging objects on the associate class through the use of +increment_counter+ 780 778 # and +decrement_counter+. The counter cache is incremented when an object of this class is created and decremented when it's 781 779 # destroyed. This requires that a column named <tt>#{table_name}_count</tt> (such as +comments_count+ for a belonging +Comment+ class) … … 925 923 # * <tt>:conditions</tt> - specify the conditions that the associated object must meet in order to be included as a +WHERE+ 926 924 # SQL fragment, such as <tt>authorized = 1</tt>. 927 # * <tt>:order</tt> - specify the order in which the associated objects are returned as a <tt>ORDER BY</tt> SQL fragment, such as <tt>last_name, first_name DESC</tt> 925 # * <tt>:order</tt> - specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment, 926 # such as <tt>last_name, first_name DESC</tt> 928 927 # * <tt>:uniq</tt> - if set to +true+, duplicate associated objects will be ignored by accessors and query methods 929 928 # * <tt>:finder_sql</tt> - overwrite the default generated SQL statement used to fetch the association with a manual statement trunk/activerecord/lib/active_record/base.rb
r8109 r8113 41 41 end 42 42 43 # Raised when you've tried to access a column ,which wasn't43 # Raised when you've tried to access a column which wasn't 44 44 # loaded by your finder. Typically this is because :select 45 45 # has been specified … … 73 73 # 74 74 # Active Records accept constructor parameters either in a hash or as a block. The hash method is especially useful when 75 # you're receiving the data from somewhere else, like a HTTP request. It works like this:75 # you're receiving the data from somewhere else, like an HTTP request. It works like this: 76 76 # 77 77 # user = User.new(:name => "David", :occupation => "Code Artist") … … 113 113 # 114 114 # The <tt>authenticate_unsafely</tt> method inserts the parameters directly into the query and is thus susceptible to SQL-injection 115 # attacks if the <tt>user_name</tt> and +password+ parameters come directly from a HTTP request. The <tt>authenticate_safely</tt> and115 # attacks if the <tt>user_name</tt> and +password+ parameters come directly from an HTTP request. The <tt>authenticate_safely</tt> and 116 116 # <tt>authenticate_safely_simply</tt> both will sanitize the <tt>user_name</tt> and +password+ before inserting them in the query, 117 117 # which will ensure that an attacker can't escape the query and fake the login (or worse). … … 138 138 # == Overwriting default accessors 139 139 # 140 # All column values are automatically available through basic accessors on the Active Record object, but some times you141 # want to specialize this behavior. This can be done by either byoverwriting the default accessors (using the same142 # name as the attribute) calling read_attribute(attr_name) and write_attribute(attr_name, value) to actually change things.140 # All column values are automatically available through basic accessors on the Active Record object, but sometimes you 141 # want to specialize this behavior. This can be done by overwriting the default accessors (using the same 142 # name as the attribute) and calling read_attribute(attr_name) and write_attribute(attr_name, value) to actually change things. 143 143 # Example: 144 144 # … … 231 231 # == Single table inheritance 232 232 # 233 # Active Record allows inheritance by storing the name of the class in a column that by default is called "type" (can be changed233 # Active Record allows inheritance by storing the name of the class in a column that by default is named "type" (can be changed 234 234 # by overwriting <tt>Base.inheritance_column</tt>). This means that an inheritance looking like this: 235 235 # … … 252 252 # Connections are usually created through ActiveRecord::Base.establish_connection and retrieved by ActiveRecord::Base.connection. 253 253 # All classes inheriting from ActiveRecord::Base will use this connection. But you can also set a class-specific connection. 254 # For example, if Course is a ActiveRecord::Base, but resides in a different databaseyou can just say Course.establish_connection254 # For example, if Course is an ActiveRecord::Base, but resides in a different database, you can just say Course.establish_connection 255 255 # and Course *and all its subclasses* will use this connection instead. 256 256 # … … 261 261 # 262 262 # * +ActiveRecordError+ -- generic error class and superclass of all other errors raised by Active Record 263 # * +AdapterNotSpecified+ -- the configuration hash used in <tt>establish_connection</tt> didn't include a 263 # * +AdapterNotSpecified+ -- the configuration hash used in <tt>establish_connection</tt> didn't include an 264 264 # <tt>:adapter</tt> key. 265 # * +AdapterNotFound+ -- the <tt>:adapter</tt> key used in <tt>establish_connection</tt> specified a nnon-existent adapter265 # * +AdapterNotFound+ -- the <tt>:adapter</tt> key used in <tt>establish_connection</tt> specified a non-existent adapter 266 266 # (or a bad spelling of an existing one). 267 267 # * +AssociationTypeMismatch+ -- the object assigned to the association wasn't of the type specified in the association definition. 268 # * +SerializationTypeMismatch+ -- the object serializedwasn't of the class specified as the second parameter.268 # * +SerializationTypeMismatch+ -- the serialized object wasn't of the class specified as the second parameter. 269 269 # * +ConnectionNotEstablished+ -- no connection has been established. Use <tt>establish_connection</tt> before querying. 270 270 # * +RecordNotFound+ -- no record responded to the find* method. … … 361 361 362 362 # Determines whether to raise an exception on mass-assignment to protected 363 # attribute . Defaults to true.363 # attributes. Defaults to true. 364 364 cattr_accessor :whiny_protected_attributes, :instance_writer => false 365 365 @@whiny_protected_attributes = true … … 371 371 # If no record can be found for all of the listed ids, then RecordNotFound will be raised. 372 372 # * Find first: This will return the first record matched by the options used. These options can either be specific 373 # conditions or merely an order. If no record can matched, nil is returned.373 # conditions or merely an order. If no record can be matched, nil is returned. 374 374 # * Find all: This will return all the records matched by the options used. If no records are found, an empty array is returned. 375 375 # 376 # All approaches accept an option hash as their last parameter. The options are:376 # All approaches accept an options hash as their last parameter. The options are: 377 377 # 378 378 # * <tt>:conditions</tt>: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ]. See conditions in the intro. … … 385 385 # The records will be returned read-only since they will have attributes that do not correspond to the table's columns. 386 386 # Pass :readonly => false to override. 387 # See adding joins for associations under Associations. 387 388 # * <tt>:include</tt>: Names associations that should be loaded alongside using LEFT OUTER JOINs. The symbols named refer 388 389 # to already defined associations. See eager loading under Associations. 389 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join,but not390 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you, for example, want to do a join but not 390 391 # include the joined columns. 391 392 # * <tt>:from</tt>: By default, this is the table name of the class, but can be changed to an alternate table name (or even the name … … 399 400 # Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6) 400 401 # Person.find([7, 17]) # returns an array for objects with IDs in (7, 17) 401 # Person.find([1]) # returns an array for objectsthe object with ID = 1402 # Person.find([1]) # returns an array for the object with ID = 1 402 403 # Person.find(1, :conditions => "administrator = 1", :order => "created_on DESC") 403 404 # … … 430 431 def find(*args) 431 432 options = args.extract_options! 433 # Note: we extract any :joins option with a non-string value from the options, and turn it into 434 # an internal option :ar_joins. This allows code called from here to find the ar_joins, and 435 # it bypasses marking the result as read_only. 436 # A normal string join marks the result as read-only because it contains attributes from joined tables 437 # which are not in the base table and therefore prevent the result from being saved. 438 # In the case of an ar_join, the JoinDependency created to instantiate the results eliminates these 439 # bogus attributes. See JoinDependency#instantiate, and JoinBase#instantiate in associations.rb. 432 440 validate_find_options(options) 433 441 set_readonly_option!(options) … … 522 530 end 523 531 524 # Destroys the objects for all the records that match the +condition + by instantiating each object and calling532 # Destroys the objects for all the records that match the +conditions+ by instantiating each object and calling 525 533 # the destroy method. Example: 526 534 # Person.destroy_all "last_login < '2004-04-04'" … … 529 537 end 530 538 531 # Deletes all the records that match the +condition + without instantiating the objects first (and hence not539 # Deletes all the records that match the +conditions+ without instantiating the objects first (and hence not 532 540 # calling the destroy method). Example: 533 541 # Post.delete_all "person_id = 5 AND (category = 'Something' OR category = 'Else')" … … 577 585 # This is used for caching aggregate values, so that they don't need to be computed every time. 578 586 # For example, a DiscussionBoard may cache post_count and comment_count otherwise every time the board is 579 # shown it would have to run a SQL query to find how many posts and comments there are.587 # shown it would have to run an SQL query to find how many posts and comments there are. 580 588 # 581 589 # ==== Options … … 688 696 # 689 697 # +attr_name+ The field name that should be serialized 690 # +class_name+ Optional, class name that the object should be equal to698 # +class_name+ Optional, class name that the object type should be equal to 691 699 # 692 700 # ==== Example … … 708 716 # directly from ActiveRecord. So if the hierarchy looks like: Reply < Message < ActiveRecord, then Message is used 709 717 # to guess the table name from even when called on Reply. The rules used to do the guess are handled by the Inflector class 710 # in Active Support, which knows almost all common English inflections (report a bug if your inflection isn't covered).718 # in Active Support, which knows almost all common English inflections. You can add new inflections in config/initializers/inflections.rb. 711 719 # 712 720 # Nested classes are given table names prefixed by the singular form of … … 965 973 end 966 974 967 # Used to sanitize objects before they're used in an S ELECT SQL-statement. Delegates to <tt>connection.quote</tt>.975 # Used to sanitize objects before they're used in an SQL SELECT statement. Delegates to <tt>connection.quote</tt>. 968 976 def sanitize(object) #:nodoc: 969 977 connection.quote(object) … … 1267 1275 # Enables dynamic finders like find_by_user_name(user_name) and find_by_user_name_and_password(user_name, password) that are turned into 1268 1276 # find(:first, :conditions => ["user_name = ?", user_name]) and find(:first, :conditions => ["user_name = ? AND password = ?", user_name, password]) 1269 # respectively. Also works for find(:all) , but using find_all_by_amount(50) that areturned into find(:all, :conditions => ["amount = ?", 50]).1277 # respectively. Also works for find(:all) by using find_all_by_amount(50) that is turned into find(:all, :conditions => ["amount = ?", 50]). 1270 1278 # 1271 1279 # It's even possible to use all the additional parameters to find. For example, the full interface for find_all_by_amount … … 1436 1444 # end 1437 1445 # 1438 # You can ignore any previous scopings by using <tt>with_exclusive_scope</tt> method.1446 # You can ignore any previous scopings by using the <tt>with_exclusive_scope</tt> method. 1439 1447 # 1440 1448 # class Article < ActiveRecord::Base … … 1890 1898 # matching the attribute names (which again matches the column names). Sensitive attributes can be protected 1891 1899 # from this form of mass-assignment by using the +attr_protected+ macro. Or you can alternatively 1892 # specify which attributes *can* be accessed inwith the +attr_accessible+ macro. Then all the1900 # specify which attributes *can* be accessed with the +attr_accessible+ macro. Then all the 1893 1901 # attributes not included in that won't be allowed to be mass-assigned. 1894 1902 def attributes=(new_attributes, guard_protected_attributes = true) … … 2121 2129 end 2122 2130 2123 # Returns copy of the attributes hash where all the values have been safely quoted for use in2131 # Returns a copy of the attributes hash where all the values have been safely quoted for use in 2124 2132 # an SQL statement. 2125 2133 def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true) … … 2160 2168 # written_on (a date type) with Date.new("2004", "6", "24"). You can also specify a typecast character in the 2161 2169 # parentheses to have the parameters typecasted before they're used in the constructor. Use i for Fixnum, f for Float, 2162 # s for String, and a for Array. If all the values for a given attribute isempty, the attribute will be set to nil.2170 # s for String, and a for Array. If all the values for a given attribute are empty, the attribute will be set to nil. 2163 2171 def assign_multiparameter_attributes(pairs) 2164 2172 execute_callstack_for_multiparameter_attributes( trunk/activerecord/lib/active_record/calculations.rb
r8109 r8113 16 16 # 17 17 # * <tt>:conditions</tt>: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ]. See conditions in the intro. 18 # * <tt>:joins</tt>: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed). 19 # The records will be returned read-only since they will have attributes that do not correspond to the table's columns. 18 # * <tt>:joins</tt>: Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed). 19 # or names associations in the same form used for the :include option. 20 # If the value is a string, then the records will be returned read-only since they will have attributes that do not correspond to the table's columns. 21 # Pass :readonly => false to override. 22 # See adding joins for associations under Associations. 20 23 # * <tt>:include</tt>: Named associations that should be loaded alongside using LEFT OUTER JOINs. The symbols named refer 21 # to already defined associations. When using named associations count returns the numberDISTINCT items for the model you're counting.24 # to already defined associations. When using named associations, count returns the number of DISTINCT items for the model you're counting. 22 25 # See eager loading under Associations. 23 26 # * <tt>:order</tt>: An SQL fragment like "created_at DESC, name" (really only used with GROUP BY calculations). 24 27 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. 25 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join,but not28 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you, for example, want to do a join but not 26 29 # include the joined columns. 27 30 # * <tt>:distinct</tt>: Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ... … … 45 48 end 46 49 47 # Calculates average value on a given column. The value is returned as a float. See #calculate for examples with options.50 # Calculates the average value on a given column. The value is returned as a float. See #calculate for examples with options. 48 51 # 49 52 # Person.average('age') … … 52 55 end 53 56 54 # Calculates the minimum value on a given column. The value is returned with the same data type of the column. .See #calculate for examples with options.57 # Calculates the minimum value on a given column. The value is returned with the same data type of the column. See #calculate for examples with options. 55 58 # 56 59 # Person.minimum('age') … … 59 62 end 60 63 61 # Calculates the maximum value on a given column. The value is returned with the same data type of the column. .See #calculate for examples with options.64 # Calculates the maximum value on a given column. The value is returned with the same data type of the column. See #calculate for examples with options. 62 65 # 63 66 # Person.maximum('age') … … 66 69 end 67 70 68 # Calculates the sum value on a given column. The value is returned with the same data type of the column.. See #calculate for examples with options.71 # Calculates the sum of values on a given column. The value is returned with the same data type of the column. See #calculate for examples with options. 69 72 # 70 73 # Person.sum('age') … … 73 76 end 74 77 75 # This calculates aggregate values in the given column :Methods for count, sum, average, minimum, and maximum have been added as shortcuts.78 # This calculates aggregate values in the given column. Methods for count, sum, average, minimum, and maximum have been added as shortcuts. 76 79 # Options such as :conditions, :order, :group, :having, and :joins can be passed to customize the query. 77 80 # … … 238 241 239 242 # Converts a given key to the value that the database adapter returns as 240 # a s ausable column name.243 # a usable column name. 241 244 # users.id #=> users_id 242 245 # sum(id) #=> sum_id trunk/activerecord/lib/active_record/callbacks.rb
r7380 r8113 162 162 # 163 163 # If the returning value of a +before_validation+ callback can be evaluated to +false+, the process will be aborted and <tt>Base#save</tt> will return +false+. 164 # If <tt>Base#save!</tt> is called it will raise a +RecordNotSave + exception.164 # If <tt>Base#save!</tt> is called it will raise a +RecordNotSaved+ exception. 165 165 # Nothing will be appended to the errors object. 166 166 # trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
r8014 r8113 244 244 245 245 # Locate the connection of the nearest super class. This can be an 246 # active or defined connection s: if it is the latter, it will be246 # active or defined connection: if it is the latter, it will be 247 247 # opened and set as the active connection for the class it was defined 248 248 # for (not necessarily the current class). … … 265 265 end 266 266 267 # Returns true if a connection that's accessible to this class ha vealready been opened.267 # Returns true if a connection that's accessible to this class has already been opened. 268 268 def self.connected? 269 269 active_connections[active_connection_name] ? true : false … … 272 272 # Remove the connection for this class. This will close the active 273 273 # connection and the defined connection (if they exist). The result 274 # can be used as a rgument for establish_connection, for easy275 # re-establishing ofthe connection.274 # can be used as an argument for establish_connection, for easily 275 # re-establishing the connection. 276 276 def self.remove_connection(klass=self) 277 277 spec = @@defined_connections[klass.name] trunk/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
r7932 r8113 99 99 end 100 100 101 # Appends +LIMIT+ and +OFFSET+ options to a SQL statement.101 # Appends +LIMIT+ and +OFFSET+ options to an SQL statement. 102 102 # This method *modifies* the +sql+ parameter. 103 103 # ===== Examples … … 114 114 end 115 115 116 # Appends a locking clause to a SQL statement. *Modifies the +sql+ parameter*. 116 # Appends a locking clause to an SQL statement. 117 # This method *modifies* the +sql+ parameter. 117 118 # # SELECT * FROM suppliers FOR UPDATE 118 119 # add_lock! 'SELECT * FROM suppliers', :lock => true trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
r8106 r8113 273 273 274 274 # Represents a SQL table in an abstract way. 275 # Columns are stored as ColumnDefinition in the #columns attribute.275 # Columns are stored as a ColumnDefinition in the #columns attribute. 276 276 class TableDefinition 277 277 attr_accessor :columns … … 452 452 453 453 # Returns a String whose contents are the column definitions 454 # concatenated together. This string can then be pre and appended to454 # concatenated together. This string can then be prepended and appended to 455 455 # to generate the final SQL to create the table. 456 456 def to_sql trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
r7932 r8113 55 55 # Make a temporary table. 56 56 # [<tt>:force</tt>] 57 # Set to true or falseto drop the table before creating it.57 # Set to true to drop the table before creating it. 58 58 # Defaults to false. 59 59 # … … 161 161 # an Array of Symbols. 162 162 # 163 # The index will be named after the table and the first column name s,163 # The index will be named after the table and the first column name, 164 164 # unless you pass +:name+ as an option. 165 165 # … … 167 167 # for the index. For example, when you specify an index on two columns 168 168 # [+:first+, +:last+], the DBMS creates an index for both columns as well as an 169 # index for the first colum +:first+. Using just the first name for this index169 # index for the first column +:first+. Using just the first name for this index 170 170 # makes sense, because you will never have to create a singular index with this 171 171 # name. trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
r8036 r8113 19 19 end 20 20 21 # The postgres drivers don't allow t o createan unconnected PGconn object,21 # The postgres drivers don't allow the creation of an unconnected PGconn object, 22 22 # so just pass a nil connection object for the time being. 23 23 ConnectionAdapters::PostgreSQLAdapter.new(nil, logger, [host, port, nil, nil, database, username, password], config) … … 218 218 # * <tt>:database</tt> -- The name of the database. No default, must be provided. 219 219 # * <tt>:schema_search_path</tt> -- An optional schema search path for the connection given as a string of comma-separated schema names. This is backward-compatible with the :schema_order option. 220 # * <tt>:encoding</tt> -- An optional client encoding that is us ing in a SET client_encoding TO <encoding> call onconnection.221 # * <tt>:min_messages</tt> -- An optional client min messages that is us ing in a SET client_min_messages TO <min_messages> call onconnection.220 # * <tt>:encoding</tt> -- An optional client encoding that is used in a SET client_encoding TO <encoding> call on the connection. 221 # * <tt>:min_messages</tt> -- An optional client min messages that is used in a SET client_min_messages TO <min_messages> call on the connection. 222 222 # * <tt>:allow_concurrency</tt> -- If true, use async query methods so Ruby threads don't deadlock; otherwise, use blocking query methods. 223 223 class PostgreSQLAdapter < AbstractAdapter … … 399 399 end 400 400 401 # Executes a SQL statement, returning a PGresult object on success401 # Executes an SQL statement, returning a PGresult object on success 402 402 # or raising a PGError exception otherwise. 403 403 def execute(sql, name = nil) … … 479 479 # Returns the list of all column definitions for a table. 480 480 def columns(table_name, name = nil) 481 # Limit, precision, and scale are all handled by superclass.481 # Limit, precision, and scale are all handled by the superclass. 482 482 column_definitions(table_name).collect do |name, type, default, notnull| 483 483 PostgreSQLColumn.new(name, default, type, notnull == 'f') … … 670 670 end 671 671 672 # Returns a ORDER BY clause for the passed order option.672 # Returns an ORDER BY clause for the passed order option. 673 673 # 674 674 # PostgreSQL does not allow arbitrary ordering when using DISTINCT ON, so we work around this … … 762 762 763 763 # Executes a SELECT query and returns the results, performing any data type 764 # conversions that requireto be performed here instead of in PostgreSQLColumn.764 # conversions that are required to be performed here instead of in PostgreSQLColumn. 765 765 def select(sql, name = nil) 766 766 fields, rows = select_raw(sql, name) … … 792 792 if res.type(cell_index) == MONEY_COLUMN_TYPE_OID 793 793 # Because money output is formatted according to the locale, there are two 794 # cases to consider (note the decimal sep erators):794 # cases to consider (note the decimal separators): 795 795 # (1) $12,345,678.12 796 796 # (2) $12.345.678,12 trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
r7753 r8113 35 35 # Allow database path relative to RAILS_ROOT, but only if 36 36 # the database path is not the special path that tells 37 # Sqlite build a database only in memory.37 # Sqlite to build a database only in memory. 38 38 if Object.const_defined?(:RAILS_ROOT) && ':memory:' != config[:database] 39 39 config[:database] = File.expand_path(config[:database], RAILS_ROOT) trunk/activerecord/lib/active_record/fixtures.rb
r8060 r8113 13 13 end 14 14 15 # Fixtures are a way of organizing data that you want to test against; in short, sample data. They come in 3 flavo urs:15 # Fixtures are a way of organizing data that you want to test against; in short, sample data. They come in 3 flavors: 16 16 # 17 17 # 1. YAML fixtures … … 22 22 # 23 23 # This type of fixture is in YAML format and the preferred default. YAML is a file format which describes data structures 24 # in a non-verbose, human ly-readable format. It ships with Ruby 1.8.1+.24 # in a non-verbose, human-readable format. It ships with Ruby 1.8.1+. 25 25 # 26 26 # Unlike single-file fixtures, YAML fixtures are stored in a single file per model, which are placed in the directory appointed … … 83 83 # = Single-file fixtures 84 84 # 85 # This type of fixture swas the original format for Active Record that has since been deprecated in favor of the YAML and CSV formats.85 # This type of fixture was the original format for Active Record that has since been deprecated in favor of the YAML and CSV formats. 86 86 # Fixtures for this format are created by placing text files in a sub-directory (with the name of the model) to the directory 87 87 # appointed by <tt>Test::Unit::TestCase.fixture_path=(path)</tt> (this is automatically configured for Rails, so you can just … … 107 107 # 108 108 # Since fixtures are a testing construct, we use them in our unit and functional tests. There are two ways to use the 109 # fixtures, but first let's take a look at a sample unit test found:109 # fixtures, but first let's take a look at a sample unit test: 110 110 # 111 111 # require 'web_site' … … 125 125 # ... 126 126 # 127 # By adding a "fixtures" method to the test case and passing it a list of symbols (only one is shown here tho ), we trigger127 # By adding a "fixtures" method to the test case and passing it a list of symbols (only one is shown here though), we trigger 128 128 # the testing environment to automatically load the appropriate fixtures into the database before each test. 129 129 # To ensure consistent data, the environment deletes the fixtures before running the load. … … 213 213 # 1. You're testing whether a transaction works correctly. Nested transactions don't commit until all parent transactions commit, 214 214 # particularly, the fixtures transaction which is begun in setup and rolled back in teardown. Thus, you won't be able to verify 215 # the results of your transaction until Active Record supports nested transactions or savepoints (in progress .)215 # the results of your transaction until Active Record supports nested transactions or savepoints (in progress). 216 216 # 2. Your database does not support transactions. Every Active Record database supports transactions except MySQL MyISAM. 217 217 # Use InnoDB, MaxDB, or NDB instead. … … 261 261 # Specifying foreign keys in fixtures can be very fragile, not to 262 262 # mention difficult to read. Since ActiveRecord can figure out the ID of 263 # an dfixture from its label, you can specify FK's by label instead of ID.263 # any fixture from its label, you can specify FK's by label instead of ID. 264 264 # 265 265 # === belongs_to trunk/activerecord/lib/active_record/migration.rb
r8031 r8113 33 33 # end 34 34 # 35 # This migration will add a boolean flag to the accounts table and remove it again,if you're backing out of the migration.35 # This migration will add a boolean flag to the accounts table and remove it if you're backing out of the migration. 36 36 # It shows how all migrations have two class methods +up+ and +down+ that describes the transformations required to implement 37 # or remove the migration. These methods can consist of both the migration specific methods ,like add_column and remove_column,37 # or remove the migration. These methods can consist of both the migration specific methods like add_column and remove_column, 38 38 # but may also contain regular Ruby code for generating data needed for the transformations. 39 39 # … … 79 79 # parameters as add_column. 80 80 # * <tt>remove_column(table_name, column_name)</tt>: Removes the column named +column_name+ from the table called +table_name+. 81 # * <tt>add_index(table_name, column_names, options)</tt>: Add a new index with the name of the column. Other options include81 # * <tt>add_index(table_name, column_names, options)</tt>: Adds a new index with the name of the column. Other options include 82 82 # :name and :unique (e.g. { :name => "users_name_index", :unique => true }). 83 # * <tt>remove_index(table_name, index_name)</tt>: Remove the index specified by +index_name+.83 # * <tt>remove_index(table_name, index_name)</tt>: Removes the index specified by +index_name+. 84 84 # 85 85 # == Irreversible transformations … … 95 95 # where MyNewMigration is the name of your migration. The generator will 96 96 # create a file <tt>nnn_my_new_migration.rb</tt> in the <tt>db/migrate/</tt> 97 # directory ,where <tt>nnn</tt> is the next largest migration number.97 # directory where <tt>nnn</tt> is the next largest migration number. 98 98 # You may then edit the <tt>self.up</tt> and <tt>self.down</tt> methods of 99 # nMyNewMigration.99 # MyNewMigration. 100 100 # 101 101 # To run migrations against the currently configured database, use trunk/activerecord/lib/active_record/reflection.rb
r7188 r8113 45 45 end 46 46 47 # Returns an array of AssociationReflection objects for all the a ggregations in the class. If you only want to reflect on a47 # Returns an array of AssociationReflection objects for all the associations in the class. If you only want to reflect on a 48 48 # certain association type, pass in the symbol (:has_many, :has_one, :belongs_to) for that as the first parameter. 49 49 # Example: … … 57 57 end 58 58 59 # Returns the AssociationReflection object for the named +a ggregation+ (use the symbol). Example:59 # Returns the AssociationReflection object for the named +association+ (use the symbol). Example: 60 60 # 61 61 # Account.reflect_on_association(:owner) # returns the owner AssociationReflection trunk/activerecord/lib/active_record/serializers/xml_serializer.rb
r8092 r8113 2 2 module Serialization 3 3 # Builds an XML document to represent the model. Some configuration is 4 # available through +options+, however more complicated cases should use4 # available through +options+, however more complicated cases should 5 5 # override ActiveRecord's to_xml. 6 6 # … … 108 108 # </firm> 109 109 # 110 # You mayoverride the to_xml method in your ActiveRecord::Base110 # You can override the to_xml method in your ActiveRecord::Base 111 111 # subclasses if you need to. The general form of doing this is 112 112 # trunk/activerecord/lib/active_record/timestamp.rb
r6789 r8113 1 1 module ActiveRecord 2 # Active Record automatically timestamps create and update if the table has fields3 # created_at/created_on or updated_at/updated_on.2 # Active Record automatically timestamps create and update operations if the table has fields 3 # named created_at/created_on or updated_at/updated_on. 4 4 # 5 5 # Timestamping can be turned off by setting trunk/activerecord/lib/active_record/transactions.rb
r8097 r8113 76 76 # Both Base#save and Base#destroy come wrapped in a transaction that ensures that whatever you do in validations or callbacks 77 77 # will happen under the protected cover of a transaction. So you can use validations to check for values that the transaction 78 # depend on or you can raise exceptions in the callbacks to rollback.78 # depends on or you can raise exceptions in the callbacks to rollback. 79 79 # 80 80 # == Exception handling trunk/activerecord/lib/active_record/validations.rb
r8000 r8113 16 16 17 17 # Active Record validation is reported to and from this object, which is used by Base#save to 18 # determine whether the object i n a valid state to be saved. See usage example in Validations.18 # determine whether the object is in a valid state to be saved. See usage example in Validations. 19 19 class Errors 20 20 include Enumerable … … 46 46 } 47 47 48 # Holds a hash with all the default error messages , such that theycan be replaced by your own copy or localizations.48 # Holds a hash with all the default error messages that can be replaced by your own copy or localizations. 49 49 cattr_accessor :default_error_messages 50 50 … … 119 119 alias :[] :on 120 120 121 # Returns errors assigned to base object through add_to_base according to the normal rules of on(attribute).121 # Returns errors assigned to the base object through add_to_base according to the normal rules of on(attribute). 122 122 def on_base 123 123 on(:base)