I'm working on creating a model that allows redirect to another
instance of the same type (Page).  For obvious reasons, I don't want
it to be able to redirect to itself. How can I get the model to
properly filter this relationship? I'm currently getting the error:

Mysql2::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 `pages`.* FROM `pages`  WHERE (id !=
#{self.id})

>From what I've read, it should be replacing #{self.id} with the
current instance.

class Page < ActiveRecord::Base
  has_ancestry
  belongs_to :footer,
    :foreign_key => 'footer_id',
    :class_name => 'ReusableText'
  belongs_to :redirect_to_page,
    :foreign_key => 'redirect_to_page_id',
    :class_name => 'Page',
    :conditions => 'id != #{self.id}'
...

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to