composite_primary_keys 13.0.7 → 14.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/History.rdoc +50 -1
 - data/README.rdoc +182 -181
 - data/Rakefile +1 -1
 - data/lib/composite_primary_keys/associations/association.rb +2 -2
 - data/lib/composite_primary_keys/associations/association_scope.rb +1 -1
 - data/lib/composite_primary_keys/associations/collection_association.rb +38 -31
 - data/lib/composite_primary_keys/associations/has_many_through_association.rb +19 -0
 - data/lib/composite_primary_keys/associations/preloader/association.rb +52 -61
 - data/lib/composite_primary_keys/autosave_association.rb +60 -60
 - data/lib/composite_primary_keys/composite_arrays.rb +88 -86
 - data/lib/composite_primary_keys/composite_predicates.rb +121 -120
 - data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +1 -2
 - data/lib/composite_primary_keys/nested_attributes.rb +2 -2
 - data/lib/composite_primary_keys/persistence.rb +96 -83
 - data/lib/composite_primary_keys/relation/calculations.rb +110 -104
 - data/lib/composite_primary_keys/relation/query_methods.rb +14 -16
 - data/lib/composite_primary_keys/relation.rb +2 -0
 - data/lib/composite_primary_keys/validations/uniqueness.rb +40 -32
 - data/lib/composite_primary_keys/version.rb +2 -2
 - data/lib/composite_primary_keys.rb +117 -119
 - data/scripts/console.rb +2 -2
 - data/tasks/databases/trilogy.rake +23 -0
 - data/test/abstract_unit.rb +124 -114
 - data/test/connections/databases.ci.yml +10 -0
 - data/test/fixtures/admin.rb +4 -0
 - data/test/fixtures/comments.yml +6 -0
 - data/test/fixtures/db_definitions/db2-create-tables.sql +34 -0
 - data/test/fixtures/db_definitions/db2-drop-tables.sql +7 -1
 - data/test/fixtures/db_definitions/mysql.sql +23 -0
 - data/test/fixtures/db_definitions/oracle.drop.sql +4 -0
 - data/test/fixtures/db_definitions/oracle.sql +21 -0
 - data/test/fixtures/db_definitions/postgresql.sql +23 -0
 - data/test/fixtures/db_definitions/sqlite.sql +21 -0
 - data/test/fixtures/db_definitions/sqlserver.sql +23 -0
 - data/test/fixtures/department.rb +20 -16
 - data/test/fixtures/moderator.rb +4 -0
 - data/test/fixtures/room.rb +4 -1
 - data/test/fixtures/room_assignment.rb +18 -14
 - data/test/fixtures/staff_room.rb +6 -0
 - data/test/fixtures/staff_room_key.rb +6 -0
 - data/test/fixtures/user.rb +3 -0
 - data/test/fixtures/user_with_polymorphic_name.rb +9 -0
 - data/test/test_associations.rb +403 -372
 - data/test/test_composite_arrays.rb +44 -38
 - data/test/test_has_one_through.rb +30 -0
 - data/test/test_nested_attributes.rb +23 -0
 - data/test/test_polymorphic.rb +6 -0
 - metadata +14 -7
 - data/lib/composite_primary_keys/associations/through_association.rb +0 -24
 
| 
         @@ -11,6 +11,8 @@ drop table streets; 
     | 
|
| 
       11 
11 
     | 
    
         
             
            drop sequence streets_seq;
         
     | 
| 
       12 
12 
     | 
    
         
             
            drop table users;
         
     | 
| 
       13 
13 
     | 
    
         
             
            drop sequence users_seq;
         
     | 
| 
      
 14 
     | 
    
         
            +
            drop table moderators;
         
     | 
| 
      
 15 
     | 
    
         
            +
            drop table admins;
         
     | 
| 
       14 
16 
     | 
    
         
             
            drop table articles;
         
     | 
| 
       15 
17 
     | 
    
         
             
            drop sequence articles_seq;
         
     | 
| 
       16 
18 
     | 
    
         
             
            drop table readings;
         
     | 
| 
         @@ -35,6 +37,8 @@ drop table room_attributes; 
     | 
|
| 
       35 
37 
     | 
    
         
             
            drop sequence room_attributes_seq;
         
     | 
| 
       36 
38 
     | 
    
         
             
            drop table room_attribute_assignments;
         
     | 
| 
       37 
39 
     | 
    
         
             
            drop table room_assignments;
         
     | 
| 
      
 40 
     | 
    
         
            +
            drop table staff_rooms;
         
     | 
| 
      
 41 
     | 
    
         
            +
            drop table staff_room_keys;
         
     | 
| 
       38 
42 
     | 
    
         
             
            drop table students;
         
     | 
| 
       39 
43 
     | 
    
         
             
            drop sequence students_seq;
         
     | 
| 
       40 
44 
     | 
    
         
             
            drop table capitols;
         
     | 
| 
         @@ -63,6 +63,14 @@ create table users ( 
     | 
|
| 
       63 
63 
     | 
    
         
             
                name varchar(50) not null
         
     | 
| 
       64 
64 
     | 
    
         
             
            );
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
      
 66 
     | 
    
         
            +
            create table moderators (
         
     | 
| 
      
 67 
     | 
    
         
            +
                id  number(11)   primary key
         
     | 
| 
      
 68 
     | 
    
         
            +
            );
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            create table admins (
         
     | 
| 
      
 71 
     | 
    
         
            +
                id  number(11)   primary key
         
     | 
| 
      
 72 
     | 
    
         
            +
            );
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
       66 
74 
     | 
    
         
             
            create sequence articles_seq start with 1000;
         
     | 
| 
       67 
75 
     | 
    
         | 
| 
       68 
76 
     | 
    
         
             
            create table articles (
         
     | 
| 
         @@ -169,6 +177,19 @@ create table room_attribute_assignments ( 
     | 
|
| 
       169 
177 
     | 
    
         
             
                room_attribute_id number(11) not null
         
     | 
| 
       170 
178 
     | 
    
         
             
            );
         
     | 
| 
       171 
179 
     | 
    
         | 
| 
      
 180 
     | 
    
         
            +
            create table staff_rooms (
         
     | 
| 
      
 181 
     | 
    
         
            +
                dorm_id  number(11) not null,
         
     | 
| 
      
 182 
     | 
    
         
            +
                room_id  number(11) not null,
         
     | 
| 
      
 183 
     | 
    
         
            +
                constraint staff_rooms_pk primary key (dorm_id, room_id)
         
     | 
| 
      
 184 
     | 
    
         
            +
            );
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
            create table staff_room_keys (
         
     | 
| 
      
 187 
     | 
    
         
            +
                dorm_id number(11) not null,
         
     | 
| 
      
 188 
     | 
    
         
            +
                room_id number(11) not null,
         
     | 
| 
      
 189 
     | 
    
         
            +
                key_no  varchar(50) not null,
         
     | 
| 
      
 190 
     | 
    
         
            +
                constraint staff_room_keys_pk primary key (dorm_id, room_id)
         
     | 
| 
      
 191 
     | 
    
         
            +
            );
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
       172 
193 
     | 
    
         
             
            create sequence students_seq start with 1000;
         
     | 
| 
       173 
194 
     | 
    
         | 
| 
       174 
195 
     | 
    
         
             
            create table students (
         
     | 
| 
         @@ -60,6 +60,16 @@ create table users ( 
     | 
|
| 
       60 
60 
     | 
    
         
             
                primary key (id)
         
     | 
| 
       61 
61 
     | 
    
         
             
            );
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
            create table moderators (
         
     | 
| 
      
 64 
     | 
    
         
            +
                id serial not null,
         
     | 
| 
      
 65 
     | 
    
         
            +
                primary key (id)
         
     | 
| 
      
 66 
     | 
    
         
            +
            );
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            create table admins (
         
     | 
| 
      
 69 
     | 
    
         
            +
                id serial not null,
         
     | 
| 
      
 70 
     | 
    
         
            +
                primary key (id)
         
     | 
| 
      
 71 
     | 
    
         
            +
            );
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
       63 
73 
     | 
    
         
             
            create table articles (
         
     | 
| 
       64 
74 
     | 
    
         
             
                id   serial not null,
         
     | 
| 
       65 
75 
     | 
    
         
             
                name varchar(50) not null,
         
     | 
| 
         @@ -154,6 +164,19 @@ create table room_attribute_assignments ( 
     | 
|
| 
       154 
164 
     | 
    
         
             
                room_attribute_id int not null
         
     | 
| 
       155 
165 
     | 
    
         
             
            );
         
     | 
| 
       156 
166 
     | 
    
         | 
| 
      
 167 
     | 
    
         
            +
            create table staff_rooms (
         
     | 
| 
      
 168 
     | 
    
         
            +
                dorm_id int not null,
         
     | 
| 
      
 169 
     | 
    
         
            +
                room_id int not null,
         
     | 
| 
      
 170 
     | 
    
         
            +
                primary key (dorm_id, room_id)
         
     | 
| 
      
 171 
     | 
    
         
            +
            );
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
            create table staff_room_keys (
         
     | 
| 
      
 174 
     | 
    
         
            +
                dorm_id int not null,
         
     | 
| 
      
 175 
     | 
    
         
            +
                room_id int not null,
         
     | 
| 
      
 176 
     | 
    
         
            +
                key_no varchar(50) not null,
         
     | 
| 
      
 177 
     | 
    
         
            +
                primary key (dorm_id, room_id)
         
     | 
| 
      
 178 
     | 
    
         
            +
            );
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
       157 
180 
     | 
    
         
             
            create table students (
         
     | 
| 
       158 
181 
     | 
    
         
             
                id serial not null,
         
     | 
| 
       159 
182 
     | 
    
         
             
                primary key (id)
         
     | 
| 
         @@ -56,6 +56,14 @@ create table users ( 
     | 
|
| 
       56 
56 
     | 
    
         
             
                name varchar(50) not null
         
     | 
| 
       57 
57 
     | 
    
         
             
            );
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
      
 59 
     | 
    
         
            +
            create table moderators (
         
     | 
| 
      
 60 
     | 
    
         
            +
                id integer not null primary key
         
     | 
| 
      
 61 
     | 
    
         
            +
            );
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            create table admins (
         
     | 
| 
      
 64 
     | 
    
         
            +
                id integer not null primary key
         
     | 
| 
      
 65 
     | 
    
         
            +
            );
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
       59 
67 
     | 
    
         
             
            create table articles (
         
     | 
| 
       60 
68 
     | 
    
         
             
                id integer not null primary key autoincrement,
         
     | 
| 
       61 
69 
     | 
    
         
             
                name varchar(50) not null
         
     | 
| 
         @@ -142,6 +150,19 @@ create table room_attribute_assignments ( 
     | 
|
| 
       142 
150 
     | 
    
         
             
            	room_attribute_id integer not null
         
     | 
| 
       143 
151 
     | 
    
         
             
            );
         
     | 
| 
       144 
152 
     | 
    
         | 
| 
      
 153 
     | 
    
         
            +
            create table staff_rooms (
         
     | 
| 
      
 154 
     | 
    
         
            +
                dorm_id integer not null,
         
     | 
| 
      
 155 
     | 
    
         
            +
                room_id integer not null,
         
     | 
| 
      
 156 
     | 
    
         
            +
                primary key (dorm_id, room_id)
         
     | 
| 
      
 157 
     | 
    
         
            +
            );
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
            create table staff_room_keys (
         
     | 
| 
      
 160 
     | 
    
         
            +
                dorm_id integer not null,
         
     | 
| 
      
 161 
     | 
    
         
            +
                room_id integer not null,
         
     | 
| 
      
 162 
     | 
    
         
            +
                key_no varchar(50) not null,
         
     | 
| 
      
 163 
     | 
    
         
            +
                primary key (dorm_id, room_id)
         
     | 
| 
      
 164 
     | 
    
         
            +
            );
         
     | 
| 
      
 165 
     | 
    
         
            +
             
     | 
| 
       145 
166 
     | 
    
         
             
            create table students (
         
     | 
| 
       146 
167 
     | 
    
         
             
            	id integer not null primary key autoincrement
         
     | 
| 
       147 
168 
     | 
    
         
             
            );
         
     | 
| 
         @@ -58,6 +58,14 @@ CREATE TABLE users ( 
     | 
|
| 
       58 
58 
     | 
    
         
             
                name varchar(50) NOT NULL
         
     | 
| 
       59 
59 
     | 
    
         
             
            );
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
      
 61 
     | 
    
         
            +
            CREATE TABLE moderators (
         
     | 
| 
      
 62 
     | 
    
         
            +
                id [int] PRIMARY KEY
         
     | 
| 
      
 63 
     | 
    
         
            +
            );
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            CREATE TABLE admins (
         
     | 
| 
      
 66 
     | 
    
         
            +
                id [int] PRIMARY KEY
         
     | 
| 
      
 67 
     | 
    
         
            +
            );
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
       61 
69 
     | 
    
         
             
            CREATE TABLE articles (
         
     | 
| 
       62 
70 
     | 
    
         
             
                id   [int] IDENTITY(1000,1) NOT NULL,
         
     | 
| 
       63 
71 
     | 
    
         
             
                name varchar(50) NOT NULL
         
     | 
| 
         @@ -148,6 +156,21 @@ CREATE TABLE room_attribute_assignments ( 
     | 
|
| 
       148 
156 
     | 
    
         
             
                room_attribute_id [int] NOT NULL
         
     | 
| 
       149 
157 
     | 
    
         
             
            );
         
     | 
| 
       150 
158 
     | 
    
         | 
| 
      
 159 
     | 
    
         
            +
            CREATE TABLE staff_rooms (
         
     | 
| 
      
 160 
     | 
    
         
            +
                dorm_id [int] NOT NULL,
         
     | 
| 
      
 161 
     | 
    
         
            +
                room_id [int] NOT NULL,
         
     | 
| 
      
 162 
     | 
    
         
            +
                CONSTRAINT [staff_rooms_pk] PRIMARY KEY CLUSTERED
         
     | 
| 
      
 163 
     | 
    
         
            +
                    ( [dorm_id], [room_id] )
         
     | 
| 
      
 164 
     | 
    
         
            +
            );
         
     | 
| 
      
 165 
     | 
    
         
            +
             
     | 
| 
      
 166 
     | 
    
         
            +
            CREATE TABLE staff_room_keys (
         
     | 
| 
      
 167 
     | 
    
         
            +
                dorm_id [int] NOT NULL,
         
     | 
| 
      
 168 
     | 
    
         
            +
                room_id [int] NOT NULL,
         
     | 
| 
      
 169 
     | 
    
         
            +
                key_no  [varchar](50) NOT NULL,
         
     | 
| 
      
 170 
     | 
    
         
            +
                CONSTRAINT [staff_room_keys_pk] PRIMARY KEY CLUSTERED
         
     | 
| 
      
 171 
     | 
    
         
            +
                    ( [dorm_id], [room_id] )
         
     | 
| 
      
 172 
     | 
    
         
            +
            );
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
       151 
174 
     | 
    
         
             
            CREATE TABLE students (
         
     | 
| 
       152 
175 
     | 
    
         
             
                id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
         
     | 
| 
       153 
176 
     | 
    
         
             
            );
         
     | 
    
        data/test/fixtures/department.rb
    CHANGED
    
    | 
         @@ -1,16 +1,20 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class Department < ActiveRecord::Base
         
     | 
| 
       2 
     | 
    
         
            -
              self.primary_keys = :id, :location_id
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
              has_many :employees,
         
     | 
| 
       5 
     | 
    
         
            -
                       # We intentionally redefine primary key for test purposes. #455
         
     | 
| 
       6 
     | 
    
         
            -
                       :primary_key =>  [:id, :location_id],
         
     | 
| 
       7 
     | 
    
         
            -
                       :foreign_key => [:department_id, :location_id]
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              has_many :comments, :through => :employees
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              has_one :head, :class_name => 'Employee',  :autosave => true, :dependent => :delete,
         
     | 
| 
       12 
     | 
    
         
            -
                             # We intentionally redefine primary key for test purposes. #455
         
     | 
| 
       13 
     | 
    
         
            -
                             :primary_key =>  [:id, :location_id],
         
     | 
| 
       14 
     | 
    
         
            -
                             :foreign_key => [:department_id, :location_id]
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            class Department < ActiveRecord::Base
         
     | 
| 
      
 2 
     | 
    
         
            +
              self.primary_keys = :id, :location_id
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              has_many :employees,
         
     | 
| 
      
 5 
     | 
    
         
            +
                       # We intentionally redefine primary key for test purposes. #455
         
     | 
| 
      
 6 
     | 
    
         
            +
                       :primary_key =>  [:id, :location_id],
         
     | 
| 
      
 7 
     | 
    
         
            +
                       :foreign_key => [:department_id, :location_id]
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              has_many :comments, :through => :employees
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              has_one :head, :class_name => 'Employee',  :autosave => true, :dependent => :delete,
         
     | 
| 
      
 12 
     | 
    
         
            +
                             # We intentionally redefine primary key for test purposes. #455
         
     | 
| 
      
 13 
     | 
    
         
            +
                             :primary_key =>  [:id, :location_id],
         
     | 
| 
      
 14 
     | 
    
         
            +
                             :foreign_key => [:department_id, :location_id]
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              has_one :head_without_autosave, :class_name => 'Employee',
         
     | 
| 
      
 17 
     | 
    
         
            +
                      # We intentionally redefine primary key for test purposes. #455
         
     | 
| 
      
 18 
     | 
    
         
            +
                      :primary_key =>  [:id, :location_id],
         
     | 
| 
      
 19 
     | 
    
         
            +
                      :foreign_key => [:department_id, :location_id]
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
    
        data/test/fixtures/room.rb
    CHANGED
    
    | 
         @@ -4,7 +4,10 @@ class Room < ActiveRecord::Base 
     | 
|
| 
       4 
4 
     | 
    
         
             
              has_many :room_assignments, :foreign_key =>  [:dorm_id, :room_id]
         
     | 
| 
       5 
5 
     | 
    
         
             
              has_many :room_attribute_assignments, :foreign_key =>  [:dorm_id, :room_id]
         
     | 
| 
       6 
6 
     | 
    
         
             
              has_many :room_attributes, :through => :room_attribute_assignments
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              has_one :staff_room, :foreign_key => [:dorm_id, :room_id], :inverse_of => :room
         
     | 
| 
      
 9 
     | 
    
         
            +
              delegate :staff_room_key, :to => :staff_room, :allow_nil => true
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       8 
11 
     | 
    
         
             
              def find_custom_room_attributes
         
     | 
| 
       9 
12 
     | 
    
         
             
                room_attributes.where("room_attributes.name != ?", "type")
         
     | 
| 
       10 
13 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,14 +1,18 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class RoomAssignment < ActiveRecord::Base
         
     | 
| 
       2 
     | 
    
         
            -
              self.primary_keys = :student_id, :dorm_id, :room_id
         
     | 
| 
       3 
     | 
    
         
            -
              belongs_to :student
         
     | 
| 
       4 
     | 
    
         
            -
              belongs_to :room, :foreign_key => [:dorm_id, :room_id], :primary_key => [:dorm_id, :room_id]
         
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
       12 
     | 
    
         
            -
                puts record
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            class RoomAssignment < ActiveRecord::Base
         
     | 
| 
      
 2 
     | 
    
         
            +
              self.primary_keys = :student_id, :dorm_id, :room_id
         
     | 
| 
      
 3 
     | 
    
         
            +
              belongs_to :student
         
     | 
| 
      
 4 
     | 
    
         
            +
              belongs_to :room, :foreign_key => [:dorm_id, :room_id], :primary_key => [:dorm_id, :room_id]
         
     | 
| 
      
 5 
     | 
    
         
            +
              validates :student_id, uniqueness: {
         
     | 
| 
      
 6 
     | 
    
         
            +
                conditions: ->(record) {
         
     | 
| 
      
 7 
     | 
    
         
            +
                  where(student_id: record.student_id) # enough just to exercise this code path
         
     | 
| 
      
 8 
     | 
    
         
            +
                }
         
     | 
| 
      
 9 
     | 
    
         
            +
              }
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              before_destroy do |record|
         
     | 
| 
      
 12 
     | 
    
         
            +
                puts record
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              after_destroy do |record|
         
     | 
| 
      
 16 
     | 
    
         
            +
                puts record
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
    
        data/test/fixtures/user.rb
    CHANGED
    
    | 
         @@ -5,6 +5,9 @@ class User < ActiveRecord::Base 
     | 
|
| 
       5 
5 
     | 
    
         
             
              has_many :comments, :as => :person
         
     | 
| 
       6 
6 
     | 
    
         
             
              has_one :first_comment, :as => :person, :class_name => "Comment"
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
      
 8 
     | 
    
         
            +
              has_one :moderator, :foreign_key => :id, :inverse_of => :user
         
     | 
| 
      
 9 
     | 
    
         
            +
              delegate :admin, :to => :moderator, :allow_nil => true
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       8 
11 
     | 
    
         
             
              def find_custom_articles
         
     | 
| 
       9 
12 
     | 
    
         
             
                articles.where("name = ?", "Article One")
         
     | 
| 
       10 
13 
     | 
    
         
             
              end
         
     |