Skip to content

Instantly share code, notes, and snippets.

@bill-transue
Created March 29, 2012 16:14
Show Gist options
  • Select an option

  • Save bill-transue/2239154 to your computer and use it in GitHub Desktop.

Select an option

Save bill-transue/2239154 to your computer and use it in GitHub Desktop.
class Cable < ActiveRecord::Base
has_many :connections, :class_name => 'Port', :autosave => false
end
class Port < ActiveRecord::Base
belongs_to :cable, :dependent => :destroy
has_many :connections, :through => :cable, :conditions => 'ports.id != #{self.id}'
end
#>> Port.last.connections.empty?
#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 ') AND ((ports.id != 1768)))' at line 1: SELECT count(*) AS count_all FROM `ports` INNER JOIN `cables` ON `ports`.cable_id = `cables`.id
#WHERE ((`cables`.id = ) AND ((ports.id != 1768)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment