Skip to content

Instantly share code, notes, and snippets.

@DBNess
Created June 6, 2012 16:15
Show Gist options
  • Save DBNess/2882994 to your computer and use it in GitHub Desktop.
Save DBNess/2882994 to your computer and use it in GitHub Desktop.
Find out if a Rails object is a child or parent through Postgres
def child?
self.connection.select_value("SELECT CASE WHEN tableoid::regclass::text = 'child_table' THEN 'true' ELSE 'false' END as child FROM parent_table WHERE id = #{self.id};")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment