checking booleans while maintaining database compatibility

Taylor Strait wrote:

  has_many :open_invitations,
            :class_name => 'Invitation',
            :conditions => "completed_at IS NULL AND is_closed = 'f'"

This works for SQLite3. But as a literal string this will fail if the
boolean values are different in another db system like MySQL, right?
How can I use a boolean in a condition that will work across all db
types?

I have done things like http://pastie.org/353140

Best Regards,

Danny

:conditions => [“completed_at IS NULL AND is_closed = ?”, false] works across databases when finding records. Does it work in a has_many declaration?

has_many :open_invitations, :class_name => …, :conditions => [“completed_at IS NULL AND is_closed = ?”, false]

Regards,
Craig

Craig Demyanovich wrote:

> types?

I have done things like http://pastie.org/353140

:conditions => ["completed_at IS NULL AND is_closed = ?", false] works
across databases when finding records. Does it work in a has_many
declaration?

has_many :open_invitations, :class_name => ..., :conditions =>
["completed_at IS NULL AND is_closed = ?", false]

Regards,
Craig

Thanks for the replies! Craig's solution worked - you CAN use a "safe
array" in the conditions of has_many. The final associations look like
this and have been confirmed working in the console:

class User
  has_many :invitations
  has_many :open_invitations,
            :class_name => 'Invitation',
            :conditions => ["completed_at IS NULL AND is_closed = ?",
false]
  has_many :closed_invitations,
            :class_name => 'Invitation',
            :conditions => ['completed_at IS NOT NULL OR is_closed = ?',
true]