Order of Join table

That was fun.

Due to some mix-up, I ended up having to rename my models. At any event, I managed to fix everything, except that I kept getting this message when I attempted to delete an entry:

ActiveRecord::StatementInvalid (Mysql::Error: Table 'development.platforms_weburls' doesn't exist: SHOW FIELDS FROM `platforms_weburls`):

The way I setup my module is that platforms and weburls are connect via the has_and_belongs_to_many association. So I was expecting for the rails up to look it up like:

weburls_platforms.

But no. :frowning:

This is the second time that happened to me and in both instances, I ended up having to rename the tables to get the models working (of note is that I had to redo the models in the first open as well - also a hbtm relation - same base table). Am I missing someplace as to how rails put together the join table names? And is there a better way of addressing it? My current tables don't look very consistent. >:(

- Rilindo

That was fun.

Due to some mix-up, I ended up having to rename my models. At any event, I managed to fix everything, except that I kept getting this message when I attempted to delete an entry:

ActiveRecord::StatementInvalid (Mysql::Error: Table ‘development.platforms_weburls’ doesn’t exist: SHOW FIELDS FROM platforms_weburls):

The way I setup my module is that platforms and weburls are connect via the has_and_belongs_to_many association. So I was expecting for the rails up to look it up like:

weburls_platforms.

But no. :frowning:

This is the second time that happened to me and in both instances, I ended up having to rename the tables to get the models working (of note is that I had to redo the models in the first open as well - also a hbtm relation - same base table). Am I missing someplace as to how rails put together the join table names? And is there a better way of addressing it? My current tables don’t look very consistent. >:(

  • Rilindo

Do you have a database table called ‘platforms_weburls’ with ‘platform_id’ and ‘weburl_id’ fields?

-Conrad

No, just:

with habtm the order is alphabetical, so platforms_weburls.

Fred

Check the documentation here: http://wiki.rubyonrails.org/howtos/db-relationships/basic

Scroll down to the habtm section and see: "Ruby will assume the name of the join table to be the concatenation of the two tables' names in alphabetical order. In our example, the join table would be assumed as courses_students. "

In your case Rails habtm expects platform_weburls because p is before w.

Thanks! I'll have to keep that in mind in future when I create my models.

Chalking this up as a newbie mistake. . .