Created
June 25, 2010 22:32
-
-
Save NickClark/453544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A Possible Bug in Rails 3? | |
With the following models, this command gives the corresponding error. | |
I think the error must reside in AREL since my assumption is that it fails since the WHERE statement is missing the id. Since the object is a new one, it doesn't have an ID, which is the reason for the error I assume from looking at the WHERE section of the sql (Should this query even be made?) | |
Model.new.contacts.size | |
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1: SELECT COUNT(*) AS count_id FROM `contacts` INNER JOIN `families` ON `contacts`.family_id = `families`.id WHERE (`contacts`.`type` = 'FamilyContact') AND ((`families`.id = )) | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:211:in `rescue in log' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:201:in `log' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:286:in `execute' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:616:in `select' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:13:in `select_one' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:19:in `select_value' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/relation/calculations.rb:174:in `execute_simple_calculation' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/relation/calculations.rb:161:in `perform_calculation' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/relation/calculations.rb:128:in `calculate' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/relation/calculations.rb:45:in `count' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/base.rb:389:in `count' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/associations/association_collection.rb:197:in `block in count' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/base.rb:1139:in `with_scope' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/associations/association_collection.rb:197:in `count' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/activerecord/lib/active_record/associations/has_many_through_association.rb:33:in `size' | |
from (irb):3 | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/railties/lib/rails/commands/console.rb:47:in `start' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/railties/lib/rails/commands/console.rb:8:in `start' | |
from /Users/nick/.rvm/gems/ruby-1.9.2-head/bundler/gems/rails-158e22d/railties/lib/rails/commands.rb:23:in `<top (required)>' | |
from script/rails:9:in `require' | |
from script/rails:9:in `<main>'ruby-1.9.2-head > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contact < ActiveRecord::Base | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Family < ActiveRecord::Base | |
has_many :contacts, :class_name => 'FamilyContact' | |
has_many :members | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FamilyContact < Contact | |
has_one :family | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Member < ActiveRecord::Base | |
belongs_to :family | |
has_many :contacts, :through => :family | |
accepts_nested_attributes_for :contacts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment