开发者

Ruby on Rails changes table names for models

开发者 https://www.devze.com 2023-04-13 09:54 出处:网络
Completely new to Rails, I read that it changes your table names because it makes a bunch of assumptions but I\'m working with tables that were created pre-rails and are used in a PHP API so I can\'t

Completely new to Rails, I read that it changes your table names because it makes a bunch of assumptions but I'm working with tables that were created pre-rails and are used in a PHP API so I can't change them.

I have a Class created in Rails that references the existing table and of course I get a sql error of table not found because it appends an s at the end of the table name, so I went ahead and put this in my Class definition:

class BookSubjects2title < ActiveRecord::Base
set_table_name "book_sub开发者_StackOverflow社区jects2title"
belongs_to :bookSubjects
end

Supposedly, that should take care of the problem from what I've read. Yet it doesn't, it still keeps trying to use the name with the s at the end and I get an error from the rails console. Is there anything I need to do for Rails to read this new config? Should be dynamic no?


Not sure if this is your only issue but

belongs_to :bookSubjects

should never have an 's', use this instead.

belongs_to :book_subject
0

精彩评论

暂无评论...
验证码 换一张
取 消