Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbuehlmann/10097696 to your computer and use it in GitHub Desktop.
Save tbuehlmann/10097696 to your computer and use it in GitHub Desktop.
[1] pry(main)> PushNotification.last.relevant_app_instances
PushNotification Load (2.2ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."type" IN ('PushNotification') ORDER BY "notifications"."id" DESC LIMIT 1
AppInstance Load (1.2ms) SELECT "app_instances".* FROM "app_instances" INNER JOIN "apps" ON "app_instances"."app_id" = "apps"."id" INNER JOIN "app_bundles" ON "apps"."app_bundle_id" = "app_bundles"."id" INNER JOIN "app_bundle_notifications" ON "app_bundles"."id" = "app_bundle_notifications"."app_bundle_id" WHERE "app_bundle_notifications"."notification_id" = $1 AND "app_instances"."app_id" IN (SELECT "apps"."id" FROM "apps" INNER JOIN "app_bundles" ON "apps"."app_bundle_id" = "app_bundles"."id" INNER JOIN "app_bundle_notifications" ON "app_bundles"."id" = "app_bundle_notifications"."app_bundle_id" WHERE "app_bundle_notifications"."notification_id" = $1 AND "apps"."type" IN ('AndroidApp', 'IosApp')) [["notification_id", 2], ["notification_id", 2]]
PG::ProtocolViolation: ERROR: bind message supplies 2 parameters, but prepared statement "a1" requires 1
: SELECT "app_instances".* FROM "app_instances" INNER JOIN "apps" ON "app_instances"."app_id" = "apps"."id" INNER JOIN "app_bundles" ON "apps"."app_bundle_id" = "app_bundles"."id" INNER JOIN "app_bundle_notifications" ON "app_bundles"."id" = "app_bundle_notifications"."app_bundle_id" WHERE "app_bundle_notifications"."notification_id" = $1 AND "app_instances"."app_id" IN (SELECT "apps"."id" FROM "apps" INNER JOIN "app_bundles" ON "apps"."app_bundle_id" = "app_bundles"."id" INNER JOIN "app_bundle_notifications" ON "app_bundles"."id" = "app_bundle_notifications"."app_bundle_id" WHERE "app_bundle_notifications"."notification_id" = $1 AND "apps"."type" IN ('AndroidApp', 'IosApp'))
Hirb Error: PG::ProtocolViolation: ERROR: bind message supplies 2 parameters, but prepared statement "a1" requires 1
: SELECT "app_instances".* FROM "app_instances" INNER JOIN "apps" ON "app_instances"."app_id" = "apps"."id" INNER JOIN "app_bundles" ON "apps"."app_bundle_id" = "app_bundles"."id" INNER JOIN "app_bundle_notifications" ON "app_bundles"."id" = "app_bundle_notifications"."app_bundle_id" WHERE "app_bundle_notifications"."notification_id" = $1 AND "app_instances"."app_id" IN (SELECT "apps"."id" FROM "apps" INNER JOIN "app_bundles" ON "apps"."app_bundle_id" = "app_bundles"."id" INNER JOIN "app_bundle_notifications" ON "app_bundles"."id" = "app_bundle_notifications"."app_bundle_id" WHERE "app_bundle_notifications"."notification_id" = $1 AND "apps"."type" IN ('AndroidApp', 'IosApp'))
class PushNotification < Notification
has_many :apps, through: :app_bundles
has_many :app_instances, through: :apps
def relevant_apps
apps.where(type: platforms)
end
def relevant_app_instances
app_instances = self.app_instances.where(app_id: relevant_apps.pluck(:id))
# using app_instances here
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment