Created
June 6, 2012 16:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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