activerecord_authorails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3043 -0
- data/README +360 -0
- data/RUNNING_UNIT_TESTS +64 -0
- data/Rakefile +226 -0
- data/examples/associations.png +0 -0
- data/examples/associations.rb +87 -0
- data/examples/shared_setup.rb +15 -0
- data/examples/validation.rb +85 -0
- data/install.rb +30 -0
- data/lib/active_record.rb +85 -0
- data/lib/active_record/acts/list.rb +244 -0
- data/lib/active_record/acts/nested_set.rb +211 -0
- data/lib/active_record/acts/tree.rb +89 -0
- data/lib/active_record/aggregations.rb +191 -0
- data/lib/active_record/associations.rb +1637 -0
- data/lib/active_record/associations/association_collection.rb +190 -0
- data/lib/active_record/associations/association_proxy.rb +158 -0
- data/lib/active_record/associations/belongs_to_association.rb +56 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +50 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +169 -0
- data/lib/active_record/associations/has_many_association.rb +210 -0
- data/lib/active_record/associations/has_many_through_association.rb +247 -0
- data/lib/active_record/associations/has_one_association.rb +80 -0
- data/lib/active_record/attribute_methods.rb +75 -0
- data/lib/active_record/base.rb +2164 -0
- data/lib/active_record/calculations.rb +270 -0
- data/lib/active_record/callbacks.rb +367 -0
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +279 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +130 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +58 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +343 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +310 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +161 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +228 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +728 -0
- data/lib/active_record/connection_adapters/frontbase_adapter.rb +861 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +414 -0
- data/lib/active_record/connection_adapters/openbase_adapter.rb +350 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +689 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +584 -0
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +407 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +591 -0
- data/lib/active_record/connection_adapters/sybase_adapter.rb +662 -0
- data/lib/active_record/deprecated_associations.rb +104 -0
- data/lib/active_record/deprecated_finders.rb +44 -0
- data/lib/active_record/fixtures.rb +628 -0
- data/lib/active_record/locking/optimistic.rb +106 -0
- data/lib/active_record/locking/pessimistic.rb +77 -0
- data/lib/active_record/migration.rb +394 -0
- data/lib/active_record/observer.rb +178 -0
- data/lib/active_record/query_cache.rb +64 -0
- data/lib/active_record/reflection.rb +222 -0
- data/lib/active_record/schema.rb +58 -0
- data/lib/active_record/schema_dumper.rb +149 -0
- data/lib/active_record/timestamp.rb +51 -0
- data/lib/active_record/transactions.rb +136 -0
- data/lib/active_record/validations.rb +843 -0
- data/lib/active_record/vendor/db2.rb +362 -0
- data/lib/active_record/vendor/mysql.rb +1214 -0
- data/lib/active_record/vendor/simple.rb +693 -0
- data/lib/active_record/version.rb +9 -0
- data/lib/active_record/wrappers/yaml_wrapper.rb +15 -0
- data/lib/active_record/wrappings.rb +58 -0
- data/lib/active_record/xml_serialization.rb +308 -0
- data/test/aaa_create_tables_test.rb +59 -0
- data/test/abstract_unit.rb +77 -0
- data/test/active_schema_test_mysql.rb +31 -0
- data/test/adapter_test.rb +87 -0
- data/test/adapter_test_sqlserver.rb +81 -0
- data/test/aggregations_test.rb +95 -0
- data/test/all.sh +8 -0
- data/test/ar_schema_test.rb +33 -0
- data/test/association_inheritance_reload.rb +14 -0
- data/test/associations/callbacks_test.rb +126 -0
- data/test/associations/cascaded_eager_loading_test.rb +138 -0
- data/test/associations/eager_test.rb +393 -0
- data/test/associations/extension_test.rb +42 -0
- data/test/associations/join_model_test.rb +497 -0
- data/test/associations_test.rb +1809 -0
- data/test/attribute_methods_test.rb +49 -0
- data/test/base_test.rb +1586 -0
- data/test/binary_test.rb +37 -0
- data/test/calculations_test.rb +219 -0
- data/test/callbacks_test.rb +377 -0
- data/test/class_inheritable_attributes_test.rb +32 -0
- data/test/column_alias_test.rb +17 -0
- data/test/connection_test_firebird.rb +8 -0
- data/test/connections/native_db2/connection.rb +25 -0
- data/test/connections/native_firebird/connection.rb +26 -0
- data/test/connections/native_frontbase/connection.rb +27 -0
- data/test/connections/native_mysql/connection.rb +24 -0
- data/test/connections/native_openbase/connection.rb +21 -0
- data/test/connections/native_oracle/connection.rb +27 -0
- data/test/connections/native_postgresql/connection.rb +23 -0
- data/test/connections/native_sqlite/connection.rb +34 -0
- data/test/connections/native_sqlite3/connection.rb +34 -0
- data/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
- data/test/connections/native_sqlserver/connection.rb +23 -0
- data/test/connections/native_sqlserver_odbc/connection.rb +25 -0
- data/test/connections/native_sybase/connection.rb +23 -0
- data/test/copy_table_sqlite.rb +64 -0
- data/test/datatype_test_postgresql.rb +52 -0
- data/test/default_test_firebird.rb +16 -0
- data/test/defaults_test.rb +60 -0
- data/test/deprecated_associations_test.rb +396 -0
- data/test/deprecated_finder_test.rb +151 -0
- data/test/empty_date_time_test.rb +25 -0
- data/test/finder_test.rb +504 -0
- data/test/fixtures/accounts.yml +28 -0
- data/test/fixtures/author.rb +99 -0
- data/test/fixtures/author_favorites.yml +4 -0
- data/test/fixtures/authors.yml +7 -0
- data/test/fixtures/auto_id.rb +4 -0
- data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +1 -0
- data/test/fixtures/bad_fixtures/attr_with_spaces +1 -0
- data/test/fixtures/bad_fixtures/blank_line +3 -0
- data/test/fixtures/bad_fixtures/duplicate_attributes +3 -0
- data/test/fixtures/bad_fixtures/missing_value +1 -0
- data/test/fixtures/binary.rb +2 -0
- data/test/fixtures/categories.yml +14 -0
- data/test/fixtures/categories/special_categories.yml +9 -0
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
- data/test/fixtures/categories_ordered.yml +7 -0
- data/test/fixtures/categories_posts.yml +23 -0
- data/test/fixtures/categorization.rb +5 -0
- data/test/fixtures/categorizations.yml +17 -0
- data/test/fixtures/category.rb +20 -0
- data/test/fixtures/column_name.rb +3 -0
- data/test/fixtures/comment.rb +23 -0
- data/test/fixtures/comments.yml +59 -0
- data/test/fixtures/companies.yml +55 -0
- data/test/fixtures/company.rb +107 -0
- data/test/fixtures/company_in_module.rb +59 -0
- data/test/fixtures/computer.rb +3 -0
- data/test/fixtures/computers.yml +4 -0
- data/test/fixtures/course.rb +3 -0
- data/test/fixtures/courses.yml +7 -0
- data/test/fixtures/customer.rb +55 -0
- data/test/fixtures/customers.yml +17 -0
- data/test/fixtures/db_definitions/db2.drop.sql +32 -0
- data/test/fixtures/db_definitions/db2.sql +231 -0
- data/test/fixtures/db_definitions/db22.drop.sql +2 -0
- data/test/fixtures/db_definitions/db22.sql +5 -0
- data/test/fixtures/db_definitions/firebird.drop.sql +63 -0
- data/test/fixtures/db_definitions/firebird.sql +304 -0
- data/test/fixtures/db_definitions/firebird2.drop.sql +2 -0
- data/test/fixtures/db_definitions/firebird2.sql +6 -0
- data/test/fixtures/db_definitions/frontbase.drop.sql +32 -0
- data/test/fixtures/db_definitions/frontbase.sql +268 -0
- data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
- data/test/fixtures/db_definitions/frontbase2.sql +4 -0
- data/test/fixtures/db_definitions/mysql.drop.sql +32 -0
- data/test/fixtures/db_definitions/mysql.sql +234 -0
- data/test/fixtures/db_definitions/mysql2.drop.sql +2 -0
- data/test/fixtures/db_definitions/mysql2.sql +5 -0
- data/test/fixtures/db_definitions/openbase.drop.sql +2 -0
- data/test/fixtures/db_definitions/openbase.sql +302 -0
- data/test/fixtures/db_definitions/openbase2.drop.sql +2 -0
- data/test/fixtures/db_definitions/openbase2.sql +7 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +65 -0
- data/test/fixtures/db_definitions/oracle.sql +325 -0
- data/test/fixtures/db_definitions/oracle2.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle2.sql +6 -0
- data/test/fixtures/db_definitions/postgresql.drop.sql +37 -0
- data/test/fixtures/db_definitions/postgresql.sql +263 -0
- data/test/fixtures/db_definitions/postgresql2.drop.sql +2 -0
- data/test/fixtures/db_definitions/postgresql2.sql +5 -0
- data/test/fixtures/db_definitions/schema.rb +60 -0
- data/test/fixtures/db_definitions/sqlite.drop.sql +32 -0
- data/test/fixtures/db_definitions/sqlite.sql +215 -0
- data/test/fixtures/db_definitions/sqlite2.drop.sql +2 -0
- data/test/fixtures/db_definitions/sqlite2.sql +5 -0
- data/test/fixtures/db_definitions/sqlserver.drop.sql +34 -0
- data/test/fixtures/db_definitions/sqlserver.sql +243 -0
- data/test/fixtures/db_definitions/sqlserver2.drop.sql +2 -0
- data/test/fixtures/db_definitions/sqlserver2.sql +5 -0
- data/test/fixtures/db_definitions/sybase.drop.sql +34 -0
- data/test/fixtures/db_definitions/sybase.sql +218 -0
- data/test/fixtures/db_definitions/sybase2.drop.sql +4 -0
- data/test/fixtures/db_definitions/sybase2.sql +5 -0
- data/test/fixtures/default.rb +2 -0
- data/test/fixtures/developer.rb +52 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +17 -0
- data/test/fixtures/developers_projects/david_action_controller +3 -0
- data/test/fixtures/developers_projects/david_active_record +3 -0
- data/test/fixtures/developers_projects/jamis_active_record +2 -0
- data/test/fixtures/edge.rb +5 -0
- data/test/fixtures/edges.yml +6 -0
- data/test/fixtures/entrant.rb +3 -0
- data/test/fixtures/entrants.yml +14 -0
- data/test/fixtures/fk_test_has_fk.yml +3 -0
- data/test/fixtures/fk_test_has_pk.yml +2 -0
- data/test/fixtures/flowers.jpg +0 -0
- data/test/fixtures/funny_jokes.yml +10 -0
- data/test/fixtures/joke.rb +6 -0
- data/test/fixtures/keyboard.rb +3 -0
- data/test/fixtures/legacy_thing.rb +3 -0
- data/test/fixtures/legacy_things.yml +3 -0
- data/test/fixtures/migrations/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations/2_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations/3_innocent_jointable.rb +12 -0
- data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
- data/test/fixtures/migrations_with_duplicate/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations_with_duplicate/2_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations_with_duplicate/3_foo.rb +7 -0
- data/test/fixtures/migrations_with_duplicate/3_innocent_jointable.rb +12 -0
- data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
- data/test/fixtures/mixed_case_monkey.rb +3 -0
- data/test/fixtures/mixed_case_monkeys.yml +6 -0
- data/test/fixtures/mixin.rb +63 -0
- data/test/fixtures/mixins.yml +127 -0
- data/test/fixtures/movie.rb +5 -0
- data/test/fixtures/movies.yml +7 -0
- data/test/fixtures/naked/csv/accounts.csv +1 -0
- data/test/fixtures/naked/yml/accounts.yml +1 -0
- data/test/fixtures/naked/yml/companies.yml +1 -0
- data/test/fixtures/naked/yml/courses.yml +1 -0
- data/test/fixtures/order.rb +4 -0
- data/test/fixtures/people.yml +3 -0
- data/test/fixtures/person.rb +4 -0
- data/test/fixtures/post.rb +58 -0
- data/test/fixtures/posts.yml +48 -0
- data/test/fixtures/project.rb +27 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/reader.rb +4 -0
- data/test/fixtures/readers.yml +4 -0
- data/test/fixtures/reply.rb +37 -0
- data/test/fixtures/subject.rb +4 -0
- data/test/fixtures/subscriber.rb +6 -0
- data/test/fixtures/subscribers/first +2 -0
- data/test/fixtures/subscribers/second +2 -0
- data/test/fixtures/tag.rb +7 -0
- data/test/fixtures/tagging.rb +6 -0
- data/test/fixtures/taggings.yml +18 -0
- data/test/fixtures/tags.yml +7 -0
- data/test/fixtures/task.rb +3 -0
- data/test/fixtures/tasks.yml +7 -0
- data/test/fixtures/topic.rb +25 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/fixtures/vertex.rb +9 -0
- data/test/fixtures/vertices.yml +4 -0
- data/test/fixtures_test.rb +401 -0
- data/test/inheritance_test.rb +205 -0
- data/test/lifecycle_test.rb +137 -0
- data/test/locking_test.rb +190 -0
- data/test/method_scoping_test.rb +416 -0
- data/test/migration_test.rb +768 -0
- data/test/migration_test_firebird.rb +124 -0
- data/test/mixin_nested_set_test.rb +196 -0
- data/test/mixin_test.rb +550 -0
- data/test/modules_test.rb +34 -0
- data/test/multiple_db_test.rb +60 -0
- data/test/pk_test.rb +104 -0
- data/test/readonly_test.rb +107 -0
- data/test/reflection_test.rb +159 -0
- data/test/schema_authorization_test_postgresql.rb +75 -0
- data/test/schema_dumper_test.rb +96 -0
- data/test/schema_test_postgresql.rb +64 -0
- data/test/synonym_test_oracle.rb +17 -0
- data/test/table_name_test_sqlserver.rb +23 -0
- data/test/threaded_connections_test.rb +48 -0
- data/test/transactions_test.rb +230 -0
- data/test/unconnected_test.rb +32 -0
- data/test/validations_test.rb +1097 -0
- data/test/xml_serialization_test.rb +125 -0
- metadata +365 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
signals37:
|
2
|
+
id: 1
|
3
|
+
firm_id: 1
|
4
|
+
credit_limit: 50
|
5
|
+
|
6
|
+
unknown:
|
7
|
+
id: 2
|
8
|
+
credit_limit: 50
|
9
|
+
|
10
|
+
rails_core_account:
|
11
|
+
id: 3
|
12
|
+
firm_id: 6
|
13
|
+
credit_limit: 50
|
14
|
+
|
15
|
+
last_account:
|
16
|
+
id: 4
|
17
|
+
firm_id: 2
|
18
|
+
credit_limit: 60
|
19
|
+
|
20
|
+
rails_core_account_2:
|
21
|
+
id: 5
|
22
|
+
firm_id: 6
|
23
|
+
credit_limit: 55
|
24
|
+
|
25
|
+
odegy_account:
|
26
|
+
id: 6
|
27
|
+
firm_id: 9
|
28
|
+
credit_limit: 53
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class Author < ActiveRecord::Base
|
2
|
+
has_many :posts
|
3
|
+
has_many :posts_with_comments, :include => :comments, :class_name => "Post"
|
4
|
+
has_many :posts_with_categories, :include => :categories, :class_name => "Post"
|
5
|
+
has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
|
6
|
+
has_many :posts_with_extension, :class_name => "Post" do #, :extend => ProxyTestExtension
|
7
|
+
def testing_proxy_owner
|
8
|
+
proxy_owner
|
9
|
+
end
|
10
|
+
def testing_proxy_reflection
|
11
|
+
proxy_reflection
|
12
|
+
end
|
13
|
+
def testing_proxy_target
|
14
|
+
proxy_target
|
15
|
+
end
|
16
|
+
end
|
17
|
+
has_many :comments, :through => :posts
|
18
|
+
has_many :funky_comments, :through => :posts, :source => :comments
|
19
|
+
|
20
|
+
has_many :special_posts
|
21
|
+
has_many :special_post_comments, :through => :special_posts, :source => :comments
|
22
|
+
|
23
|
+
has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
|
24
|
+
has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
|
25
|
+
|
26
|
+
has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'"
|
27
|
+
has_many :hello_post_comments, :through => :hello_posts, :source => :comments
|
28
|
+
|
29
|
+
has_many :other_posts, :class_name => "Post"
|
30
|
+
has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
|
31
|
+
:after_add => :log_after_adding,
|
32
|
+
:before_remove => :log_before_removing,
|
33
|
+
:after_remove => :log_after_removing
|
34
|
+
has_many :posts_with_proc_callbacks, :class_name => "Post",
|
35
|
+
:before_add => Proc.new {|o, r| o.post_log << "before_adding#{r.id}"},
|
36
|
+
:after_add => Proc.new {|o, r| o.post_log << "after_adding#{r.id}"},
|
37
|
+
:before_remove => Proc.new {|o, r| o.post_log << "before_removing#{r.id}"},
|
38
|
+
:after_remove => Proc.new {|o, r| o.post_log << "after_removing#{r.id}"}
|
39
|
+
has_many :posts_with_multiple_callbacks, :class_name => "Post",
|
40
|
+
:before_add => [:log_before_adding, Proc.new {|o, r| o.post_log << "before_adding_proc#{r.id}"}],
|
41
|
+
:after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id}"}]
|
42
|
+
has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
|
43
|
+
|
44
|
+
has_many :categorizations
|
45
|
+
has_many :categories, :through => :categorizations
|
46
|
+
|
47
|
+
has_many :categories_like_general, :through => :categorizations, :source => :category, :class_name => 'Category', :conditions => { :name => 'General' }
|
48
|
+
|
49
|
+
has_many :categorized_posts, :through => :categorizations, :source => :post
|
50
|
+
has_many :unique_categorized_posts, :through => :categorizations, :source => :post, :uniq => true
|
51
|
+
|
52
|
+
has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
|
53
|
+
|
54
|
+
has_many :author_favorites
|
55
|
+
has_many :favorite_authors, :through => :author_favorites, :order => 'name'
|
56
|
+
|
57
|
+
has_many :tagging, :through => :posts # through polymorphic has_one
|
58
|
+
has_many :taggings, :through => :posts, :source => :taggings # through polymorphic has_many
|
59
|
+
has_many :tags, :through => :posts # through has_many :through
|
60
|
+
has_many :post_categories, :through => :posts, :source => :categories
|
61
|
+
|
62
|
+
belongs_to :author_address
|
63
|
+
|
64
|
+
attr_accessor :post_log
|
65
|
+
|
66
|
+
def after_initialize
|
67
|
+
@post_log = []
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def log_before_adding(object)
|
72
|
+
@post_log << "before_adding#{object.id}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def log_after_adding(object)
|
76
|
+
@post_log << "after_adding#{object.id}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def log_before_removing(object)
|
80
|
+
@post_log << "before_removing#{object.id}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def log_after_removing(object)
|
84
|
+
@post_log << "after_removing#{object.id}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def raise_exception(object)
|
88
|
+
raise Exception.new("You can't add a post")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class AuthorAddress < ActiveRecord::Base
|
93
|
+
has_one :author
|
94
|
+
end
|
95
|
+
|
96
|
+
class AuthorFavorite < ActiveRecord::Base
|
97
|
+
belongs_to :author
|
98
|
+
belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id'
|
99
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
1b => 1
|
@@ -0,0 +1 @@
|
|
1
|
+
a b => 1
|
@@ -0,0 +1 @@
|
|
1
|
+
a =>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
general_welcome:
|
2
|
+
category_id: 1
|
3
|
+
post_id: 1
|
4
|
+
|
5
|
+
technology_welcome:
|
6
|
+
category_id: 2
|
7
|
+
post_id: 1
|
8
|
+
|
9
|
+
general_thinking:
|
10
|
+
category_id: 1
|
11
|
+
post_id: 2
|
12
|
+
|
13
|
+
general_sti_habtm:
|
14
|
+
category_id: 1
|
15
|
+
post_id: 6
|
16
|
+
|
17
|
+
sti_test_sti_habtm:
|
18
|
+
category_id: 3
|
19
|
+
post_id: 6
|
20
|
+
|
21
|
+
general_hello:
|
22
|
+
category_id: 1
|
23
|
+
post_id: 4
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Category < ActiveRecord::Base
|
2
|
+
has_and_belongs_to_many :posts
|
3
|
+
has_and_belongs_to_many :special_posts, :class_name => "Post"
|
4
|
+
has_and_belongs_to_many :other_posts, :class_name => "Post"
|
5
|
+
|
6
|
+
def self.what_are_you
|
7
|
+
'a category...'
|
8
|
+
end
|
9
|
+
|
10
|
+
has_many :categorizations
|
11
|
+
has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'
|
12
|
+
end
|
13
|
+
|
14
|
+
class SpecialCategory < Category
|
15
|
+
|
16
|
+
def self.what_are_you
|
17
|
+
'a special category...'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Comment < ActiveRecord::Base
|
2
|
+
belongs_to :post
|
3
|
+
|
4
|
+
def self.what_are_you
|
5
|
+
'a comment...'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.search_by_type(q)
|
9
|
+
self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class SpecialComment < Comment
|
14
|
+
def self.what_are_you
|
15
|
+
'a special comment...'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class VerySpecialComment < Comment
|
20
|
+
def self.what_are_you
|
21
|
+
'a very special comment...'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
greetings:
|
2
|
+
id: 1
|
3
|
+
post_id: 1
|
4
|
+
body: Thank you for the welcome
|
5
|
+
type: Comment
|
6
|
+
|
7
|
+
more_greetings:
|
8
|
+
id: 2
|
9
|
+
post_id: 1
|
10
|
+
body: Thank you again for the welcome
|
11
|
+
type: Comment
|
12
|
+
|
13
|
+
does_it_hurt:
|
14
|
+
id: 3
|
15
|
+
post_id: 2
|
16
|
+
body: Don't think too hard
|
17
|
+
type: SpecialComment
|
18
|
+
|
19
|
+
eager_sti_on_associations_vs_comment:
|
20
|
+
id: 5
|
21
|
+
post_id: 4
|
22
|
+
body: Very Special type
|
23
|
+
type: VerySpecialComment
|
24
|
+
|
25
|
+
eager_sti_on_associations_s_comment1:
|
26
|
+
id: 6
|
27
|
+
post_id: 4
|
28
|
+
body: Special type
|
29
|
+
type: SpecialComment
|
30
|
+
|
31
|
+
eager_sti_on_associations_s_comment2:
|
32
|
+
id: 7
|
33
|
+
post_id: 4
|
34
|
+
body: Special type 2
|
35
|
+
type: SpecialComment
|
36
|
+
|
37
|
+
eager_sti_on_associations_comment:
|
38
|
+
id: 8
|
39
|
+
post_id: 4
|
40
|
+
body: Normal type
|
41
|
+
type: Comment
|
42
|
+
|
43
|
+
check_eager_sti_on_associations:
|
44
|
+
id: 9
|
45
|
+
post_id: 5
|
46
|
+
body: Normal type
|
47
|
+
type: Comment
|
48
|
+
|
49
|
+
check_eager_sti_on_associations2:
|
50
|
+
id: 10
|
51
|
+
post_id: 5
|
52
|
+
body: Special Type
|
53
|
+
type: SpecialComment
|
54
|
+
|
55
|
+
eager_other_comment1:
|
56
|
+
id: 11
|
57
|
+
post_id: 7
|
58
|
+
body: go crazy
|
59
|
+
type: SpecialComment
|
@@ -0,0 +1,55 @@
|
|
1
|
+
first_client:
|
2
|
+
id: 2
|
3
|
+
type: Client
|
4
|
+
firm_id: 1
|
5
|
+
client_of: 2
|
6
|
+
name: Summit
|
7
|
+
ruby_type: Client
|
8
|
+
|
9
|
+
first_firm:
|
10
|
+
id: 1
|
11
|
+
type: Firm
|
12
|
+
name: 37signals
|
13
|
+
ruby_type: Firm
|
14
|
+
|
15
|
+
second_client:
|
16
|
+
id: 3
|
17
|
+
type: Client
|
18
|
+
firm_id: 1
|
19
|
+
client_of: 1
|
20
|
+
name: Microsoft
|
21
|
+
ruby_type: Client
|
22
|
+
|
23
|
+
another_firm:
|
24
|
+
id: 4
|
25
|
+
type: Firm
|
26
|
+
name: Flamboyant Software
|
27
|
+
ruby_type: Firm
|
28
|
+
|
29
|
+
another_client:
|
30
|
+
id: 5
|
31
|
+
type: Client
|
32
|
+
firm_id: 4
|
33
|
+
client_of: 4
|
34
|
+
name: Ex Nihilo
|
35
|
+
ruby_type: Client
|
36
|
+
|
37
|
+
rails_core:
|
38
|
+
id: 6
|
39
|
+
name: RailsCore
|
40
|
+
type: DependentFirm
|
41
|
+
|
42
|
+
leetsoft:
|
43
|
+
id: 7
|
44
|
+
name: Leetsoft
|
45
|
+
client_of: 6
|
46
|
+
|
47
|
+
jadedpixel:
|
48
|
+
id: 8
|
49
|
+
name: Jadedpixel
|
50
|
+
client_of: 6
|
51
|
+
|
52
|
+
odegy:
|
53
|
+
id: 9
|
54
|
+
name: Odegy
|
55
|
+
type: ExclusivelyDependentFirm
|
@@ -0,0 +1,107 @@
|
|
1
|
+
class Company < ActiveRecord::Base
|
2
|
+
attr_protected :rating
|
3
|
+
set_sequence_name :companies_nonstd_seq
|
4
|
+
|
5
|
+
validates_presence_of :name
|
6
|
+
|
7
|
+
has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
|
8
|
+
|
9
|
+
def arbitrary_method
|
10
|
+
"I am Jack's profound disappointment"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
class Firm < Company
|
16
|
+
has_many :clients, :order => "id", :dependent => :destroy, :counter_sql =>
|
17
|
+
"SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
|
18
|
+
"AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
|
19
|
+
has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
|
20
|
+
has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
|
21
|
+
has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy
|
22
|
+
has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
|
23
|
+
has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1
|
24
|
+
has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
|
25
|
+
has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
|
26
|
+
has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
|
27
|
+
has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
|
28
|
+
has_many :clients_using_counter_sql, :class_name => "Client",
|
29
|
+
:finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
|
30
|
+
:counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'
|
31
|
+
has_many :clients_using_zero_counter_sql, :class_name => "Client",
|
32
|
+
:finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
|
33
|
+
:counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}'
|
34
|
+
has_many :no_clients_using_counter_sql, :class_name => "Client",
|
35
|
+
:finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
|
36
|
+
:counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
|
37
|
+
has_many :plain_clients, :class_name => 'Client'
|
38
|
+
|
39
|
+
has_one :account, :foreign_key => "firm_id", :dependent => :destroy
|
40
|
+
end
|
41
|
+
|
42
|
+
class DependentFirm < Company
|
43
|
+
has_one :account, :foreign_key => "firm_id", :dependent => :nullify
|
44
|
+
has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
|
45
|
+
end
|
46
|
+
|
47
|
+
class ExclusivelyDependentFirm < Company
|
48
|
+
has_one :account, :foreign_key => "firm_id", :dependent => :delete
|
49
|
+
end
|
50
|
+
|
51
|
+
class Client < Company
|
52
|
+
belongs_to :firm, :foreign_key => "client_of"
|
53
|
+
belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
|
54
|
+
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
|
55
|
+
belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
|
56
|
+
|
57
|
+
# Record destruction so we can test whether firm.clients.clear has
|
58
|
+
# is calling client.destroy, deleting from the database, or setting
|
59
|
+
# foreign keys to NULL.
|
60
|
+
def self.destroyed_client_ids
|
61
|
+
@destroyed_client_ids ||= Hash.new { |h,k| h[k] = [] }
|
62
|
+
end
|
63
|
+
|
64
|
+
before_destroy do |client|
|
65
|
+
if client.firm
|
66
|
+
Client.destroyed_client_ids[client.firm.id] << client.id
|
67
|
+
end
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
# Used to test that read and question methods are not generated for these attributes
|
72
|
+
def ruby_type
|
73
|
+
read_attribute :ruby_type
|
74
|
+
end
|
75
|
+
|
76
|
+
def rating?
|
77
|
+
query_attribute :rating
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
class SpecialClient < Client
|
83
|
+
end
|
84
|
+
|
85
|
+
class VerySpecialClient < SpecialClient
|
86
|
+
end
|
87
|
+
|
88
|
+
class Account < ActiveRecord::Base
|
89
|
+
belongs_to :firm
|
90
|
+
|
91
|
+
def self.destroyed_account_ids
|
92
|
+
@destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
|
93
|
+
end
|
94
|
+
|
95
|
+
before_destroy do |account|
|
96
|
+
if account.firm
|
97
|
+
Account.destroyed_account_ids[account.firm.id] << account.id
|
98
|
+
end
|
99
|
+
true
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
protected
|
104
|
+
def validate
|
105
|
+
errors.add_on_empty "credit_limit"
|
106
|
+
end
|
107
|
+
end
|