Includes HABTM returns correct size now. Fixes #16032 and #15244 for master

    Includes HABTM returns correct size now. It's caused by the join dependency only instantiates one HABTM object because the join table hasn't a primary key.
    Updated commit and test fixed from @bigxiang commit dbaa837

    Fixes #16032.

    Examples:

        before:

        Project.first.salaried_developers.size # => 3
        Project.includes(:salaried_developers).first.salaried_developers.size # => 1

        after:

        Project.first.salaried_developers.size # => 3
        Project.includes(:salaried_developers).first.salaried_developers.size # => 3
  has_and_belongs_to_many :developers_named_david, -> { where("name = 'David'").distinct }, :class_name => "Developer" 
reflection scope for this association has no :references key, so preloader code calls references with nil and it sets references_values to [""], then eager_loading? returns true because references_eager_loaded_tables? (references_values - joined_tables is [""]). Then a left join query is used, which is needed to get conditions working.

  has_and_belongs_to_many :developers_named_david_with_hash_conditions, -> { where(:name => 'David').distinct }, :class_name => "Developer" 
reflection scope for this association has :references key as [], so preloader code calls references with [] and it sets references_values to [], and eager_loading? returns false. Then a left join query is not used, which are needed for conditions, and SQL error is raised.

What do you think? Is it a bug? Or should associations include a references(:developers) to get it working? @eileencodes suggested me to use references, but maybe I didn't understand her, and references must be added to HABTM definition. However it sounds weird to me:

  has_and_belongs_to_many :developers_named_david_with_hash_conditions, -> { where(:name => 'David').references(:developers).distinct }, :class_name => "Developer" 

That works, but references(:developers) on HABTM developers sounds weird.

This works too:
  has_and_belongs_to_many :developers_named_david_with_hash_conditions, -> { where(:developers => {:name => 'David'}).distinct }, :class_name => "Developer"