mirror of https://github.com/rails/rails
Added ActiveRecord::Mixins::List that can decorates an existing class with methods like move_higher/lower, move_to_top/bottom
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@84 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
55be0a3cb5
commit
1cf7eb1ca8
|
@ -1,5 +1,17 @@
|
||||||
*CVS*
|
*CVS*
|
||||||
|
|
||||||
|
* Added ActiveRecord::Mixins::List that can decorates an existing class with methods like move_higher/lower, move_to_top/bottom. Example:
|
||||||
|
|
||||||
|
class TodoItem < ActiveRecord::Base
|
||||||
|
include ActiveRecord::Mixins::List
|
||||||
|
belongs_to :todo_list
|
||||||
|
|
||||||
|
private
|
||||||
|
def scope_condition
|
||||||
|
"todo_list_id = #{todo_list_id}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
* Added the option for sanitizing find_by_sql and the offset parts in regular finds [Sam Stephenson]. Examples:
|
* Added the option for sanitizing find_by_sql and the offset parts in regular finds [Sam Stephenson]. Examples:
|
||||||
|
|
||||||
Project.find_all ["category = ?", category_name], "created ASC", ["? OFFSET ?", 15, 20]
|
Project.find_all ["category = ?", category_name], "created ASC", ["? OFFSET ?", 15, 20]
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
|
# Mixins are a way of decorating existing Active Record models with additional behavior. If you for example
|
||||||
|
# want to keep a number of Documents in order, you can include Mixins::List, and all of the sudden be able to
|
||||||
|
# call <tt>document.move_to_bottom</tt>.
|
||||||
module Mixins
|
module Mixins
|
||||||
# This mixin provides the capabilities for sorting and reordering a number of objects in list.
|
# This mixin provides the capabilities for sorting and reordering a number of objects in list.
|
||||||
# The class that has this mixin included needs to have a "position" column defined as an integer on
|
# The class that has this mixin included needs to have a "position" column defined as an integer on
|
||||||
|
@ -12,7 +15,7 @@ module ActiveRecord
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# class TodoItem < ActiveRecord::Base
|
# class TodoItem < ActiveRecord::Base
|
||||||
# include ListMixin
|
# include ActiveRecord::Mixins::List
|
||||||
# belongs_to :todo_list
|
# belongs_to :todo_list
|
||||||
#
|
#
|
||||||
# private
|
# private
|
||||||
|
|
Loading…
Reference in New Issue