|
Revision 9068, 0.9 kB
(checked in by rick, 8 months ago)
|
Allow association scoping for built/created records if :conditions is specified as a hash. Closes #11393 [miloops]
|
| Line | |
|---|
| 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 |
has_and_belongs_to_many(:select_testing_posts, |
|---|
| 7 |
:class_name => 'Post', |
|---|
| 8 |
:foreign_key => 'category_id', |
|---|
| 9 |
:association_foreign_key => 'post_id', |
|---|
| 10 |
:select => 'posts.*, 1 as correctness_marker') |
|---|
| 11 |
|
|---|
| 12 |
has_and_belongs_to_many :post_with_conditions, |
|---|
| 13 |
:class_name => 'Post', |
|---|
| 14 |
:conditions => { :title => 'Yet Another Testing Title' } |
|---|
| 15 |
def self.what_are_you |
|---|
| 16 |
'a category...' |
|---|
| 17 |
end |
|---|
| 18 |
|
|---|
| 19 |
has_many :categorizations |
|---|
| 20 |
has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id' |
|---|
| 21 |
end |
|---|
| 22 |
|
|---|
| 23 |
class SpecialCategory < Category |
|---|
| 24 |
|
|---|
| 25 |
def self.what_are_you |
|---|
| 26 |
'a special category...' |
|---|
| 27 |
end |
|---|
| 28 |
|
|---|
| 29 |
end |
|---|