#163 ✓resolved
Paul Cantrell

Custom table name breaks habtm

Reported by Paul Cantrell | February 21st, 2008 @ 04:22 PM

To reproduce, create two model objects:

class Foo < DataMapper::Base

has_and_belongs_to_many :bars


class Bar < DataMapper::Base

has_and_belongs_to_many :foos


Now do Foo.all.first.bars, and this generates the expected query:

SELECT "bars"."id", "bars_foos"."bar_id", "bars_foos"."foo_id"

FROM "bars"

JOIN "bars_foos" ON "bars_foos"."bar_id" = "bars"."id"

WHERE ("bars_foos"."foo_id" IN (1)

However, if we give foo a custom name — any name:

class Foo < DataMapper::Base

set_table_name 'foox'

has_and_belongs_to_many :bars


...then suddenly DM generates a bogus, query as if it were a has_many


SELECT "id" FROM "bars" WHERE ("foox_id" IN (1))

The attached patch fixes the name mismatch bug.

It does not fix the problem that LoadCommand silently swallows the bad association name and generates the wrong query, instead of generating a good error.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket