Skip to content
Tags

clauses with sql string in scopes

March 1, 2013

When writing clauses that include sql strings within scopes, it is a good practice to include table names.

“`ruby

scope :published, where(‘published_at IS NOT NULL’);

scope :published, where(‘resources.published_at IS NOT NULL’)

scope :published, where(:published => true)

“`

This is because since scopes can be chained, and merged, there can come a time when sql gives an error for not being sure about which table.

When using the hash, rails does it automatically and so it is not required.

Got this tip from the amazing ryan bates

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: