schema_associations 1.0.0 → 1.0.1

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.
data/README.rdoc CHANGED
@@ -309,6 +309,10 @@ If you're running ruby 1.9, code coverage results will be in coverage/index.html
309
309
 
310
310
  == Release notes:
311
311
 
312
+ === 1.0.1
313
+
314
+ * Bug fix: use singular :inverse_of for :belongs_to of a :has_one
315
+
312
316
  === 1.0.0
313
317
 
314
318
  * Use :inverse_of in generated associations
@@ -114,7 +114,7 @@ module SchemaAssociations
114
114
  when :belongs_to
115
115
  name = names[:belongs_to]
116
116
  opts = {:class_name => references_class_name, :foreign_key => column_name}
117
- if connection.indexes(fk.references_table_name, "#{fk.references_table_name} Indexes").any?{|index| index.unique && index.columns == [column_name]}
117
+ if connection.indexes(referencing_table_name).any?{|index| index.unique && index.columns == [column_name]}
118
118
  opts[:inverse_of] = names[:has_one]
119
119
  else
120
120
  opts[:inverse_of] = names[:has_many]
@@ -127,13 +127,13 @@ module SchemaAssociations
127
127
  # methods would require getting the class -- which might trigger
128
128
  # an autoload which could start some recursion making things much
129
129
  # harder to debug.
130
- if connection.indexes(referencing_table_name, "#{referencing_table_name} Indexes").any?{|index| index.unique && index.columns == [column_name]}
130
+ if connection.indexes(referencing_table_name).any?{|index| index.unique && index.columns == [column_name]}
131
131
  macro = :has_one
132
132
  name = names[:has_one]
133
133
  else
134
134
  macro = :has_many
135
135
  name = names[:has_many]
136
- if connection.columns(referencing_table_name, "#{referencing_table_name} Columns").any?{ |col| col.name == 'position' }
136
+ if connection.columns(referencing_table_name).any?{ |col| col.name == 'position' }
137
137
  opts[:order] = :position
138
138
  end
139
139
  end
@@ -1,3 +1,3 @@
1
1
  module SchemaAssociations
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -227,6 +227,14 @@ describe ActiveRecord::Base do
227
227
  reflection.options[:foreign_key].should == "post_id"
228
228
  reflection.options[:inverse_of].should == :post
229
229
  end
230
+ it "should create belongs_to association with singular inverse" do
231
+ reflection = Comment.reflect_on_association(:post)
232
+ reflection.should_not be_nil
233
+ reflection.macro.should == :belongs_to
234
+ reflection.options[:class_name].should == "Post"
235
+ reflection.options[:foreign_key].should == "post_id"
236
+ reflection.options[:inverse_of].should == :comment
237
+ end
230
238
  end
231
239
 
232
240
  context "with prefixed column names" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: