
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
end
class Bar < DataMapper::Base
has_and_belongs_to_many :foos
end
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
end
...then suddenly DM generates a bogus, query as if it were a has_many
association:
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
-
Dan Kubb (dkubb) April 15th, 2008 @ 03:17 AM
- Milestone cleared.
-
Sam Smoot May 8th, 2008 @ 05:08 PM
- Assigned user set to Adam French
Adam, please apply to DM 0.3.0 and close out the ticket.
-
-
Adam French May 8th, 2008 @ 05:15 PM
- State changed from new to resolved
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »