I have relation has\_many - has\_many like :

```
class baz < ActiveRecord::Base
    has_many :foo
    has_many :bar, through: :foo
end

class foo < ActiveRecord::Base
   belongs_to :baz
   belongs_to :bar
end

class bar < ActiveRecord::Base
   has_many :foo
   has_many :baz, through: :foo
end

```

if I do `Baz.first.bar_ids`, rails join on bar table instead of get bar\_id in foo table... Why? It's useless jointer

SQL log :

```
 SELECT `bar`.id FROM `bar` INNER JOIN `foo` ON `bar`.`id` = `foo`.`bar_id` WHERE `foo`.`baz_id` = 1

```

expected :

```
 SELECT [DISTINCT] `foo`.bar_id FROM `foo` WHERE `foo`.`baz_id` = 1

```