module RubyWedding
  class Invitation < ActiveRecord::Base
    has_many :guests, class_name: "RubyWedding::Guest"

    accepts_nested_attributes_for :guests

    validates :notes, length: { maximum: 2000 }

    def self.find_by_guest_surname(surname)
      includes(:guests).where('ruby_wedding_guests.surname' => surname).distinct
    end

    def guest_list
      guests.map(&:fullname).to_sentence(last_word_connector: ' & ')
    end

    def contains_children?
      guests.any?(&:child?)
    end

  end
end

module RubyWedding
  class Invitation < ActiveRecord::Base
    has_many :guests, class_name: "RubyWedding::Guest"

    accepts_nested_attributes_for :guests

    validates :notes, length: { maximum: 2000 }

    def self.find_by_guest_surname(surname)
      includes(:guests).where('ruby_wedding_guests.surname' => surname).distinct
    end

    def guest_list
      guests.all.map(&:fullname).to_sentence(last_word_connector: ' & ')
    end

    def contains_children?
      guests.any?(&:child?)
    end

  end
end

Add .all to guests in guest_list
Add .all to guests in guest_list

If an invitation was loaded by a .join on the 'guests' table
(which happens when searching for an inviation by guest name),
and all the guests didn’t match the join conditions,
then all guests are not present on the in-memory invitation, meaning
they weren’t output on the guest_list.
