Joins parent and child tables in rails
1. Get parent objects: Alert.joins("LEFT JOIN alert_events on alert_events.alert_id = alerts.id ").group(' alerts.id ').select(' alerts.*') 2. Get Child Object: AlertEvent.joins("INNER JOIN alerts on alerts.id = alert_events.alert_id ").group(' alert_events.id ').se lect('alert_events.*') Active record for child object AlertEvent.joins(:alert).where (alerts: {category: 'Pay'}) 3. Joins multiple tables: @previous_seafood_items = SeafoodItem.joins("LEFT JOIN auction_items on auction_items.itemable_id = seafood_items.id and auction_items.itemable_type = 'SeafoodItem' and auction_items.auction_id is NULL") .group('seafood_items.id') .select('seafood_items.*') .where(user_id: current_user.id ) .paginate(:page => params[:page], :per_page => 20)