Skip to content

has_and_belongs_to_many relationships will not store join table #38

@bessey

Description

@bessey

Title perhaps doesn't explain the problem well, code does:

class Account
  has_and_belongs_to_many :roles
end

class Role
  has_and_belongs_to_many :accounts
end

account = Account.create name: "Matt"
role = Role.create name: "admin"

account.roles << role

Polo.explore(Account, [1,2,3], [:roles])

This will result in the INSERT SQL for account and role being created, but not for the join table. The "solution" appears to be to use has_many through: instead, and always have an AR model with an ID column as the join table.

I don't have a solution, so I feel the README should at least clarify that HABTM doesn't work right now, and to use has_many through: instead.

Encountered on Rails 3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions