I'm building a marketplace app on rails 4. I have a seller widget that displays a random list of sellers on our platform. Sometimes, sellers' listings expire so they don't have any items for sale. I want to exclude these sellers from appearing in the widget.
I have a User model (users can be buyers or sellers). Sellers have a profile description and image while buyers do not. So to create the widget, I use the below query.
<% User.where("profileimage_file_name != ? AND profilestory != ?", "", "").order("random()").limit(12).each do |user| %>
#some code to link to seller page
<% end %>
I have a Listing model which stores all the product listings and has a user_id as a foreign key.
The User model doesn't have any listings data. How do I write the query so I can join the User Model with the Listings model and only show Users who have at least 1 listing active.