I have two models that Has and Belongs To Many join to. Lets name these models User and Event. Most users have 0 events, while few have one or more. I want to do something like:
User.find (: all ,: joins =>: events ,: conditions => [" " Something that counts events >? "], 0)
The problem is that I'm not sure how to select only users who have 1 or more related events.
I found the answer:
User.find(:all, :joins => :events, :select => 'DISTINCT `users`.*')
In principle, users . * restricts the result set to only the user table, and the DISTINCT keyword ensures that each user is returned only once.
users
Source: https://habr.com/ru/post/1277755/More articles:Start storyboard in the next schedule scale - animationSaving user login time - javascriptWhat is the best sound compression library for .NET? - c #CSS Performance - performanceContext help in Visual Studio - c #Java Servlets: performance - javahttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1277757/any-way-to-ignore-files-coming-from-the-repository-for-ntfs&usg=ALkJrhj4sM0UCGEu07NKR8mgbhcPMTBGTgInternationalization in Visual Studio - visual-studioShowing a newly added table row using .show ("slow") - jqueryHow to get C # Query component to recognize columns returned by data from temporary table in sql stored procedure - c #All Articles