Skip to content

Instantly share code, notes, and snippets.

@VictorTpo
Last active August 29, 2015 14:06
Show Gist options
  • Save VictorTpo/4c47e4fd3083b3cefe80 to your computer and use it in GitHub Desktop.
Save VictorTpo/4c47e4fd3083b3cefe80 to your computer and use it in GitHub Desktop.

##Merge many has_many

def get_fb_users
	FacebookUser.from("
		(
			(
				#{self.facebook_recipients_users.to_sql}
			) union (
				#{self.facebook_users.to_sql}
			)
		) #{FacebookUser.table_name}
	")
end

Peut aussi être fait autrement (mais BEAUCOUP moins rapide):

def get_fb_users
	fromable_users = self.facebook_users.pluck(:id)
	postable_users = self.facebook_recipients_users.pluck(:id)
	all_users_ids = (fromable_users+postable_users).uniq
	res = FacebookUser.where(id: all_users_ids)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment