开发者

Rails Join Table without Model

Is it possible to create a join table without a model. I have a model called User and Pet. I want user to have only one pet and pet to on开发者_如何学运维ly have one owner. Very simple. However, I am trying to figure out how to create a join table

pets_users that has both users.id and pets.id in it without having to create the actual model. Is this possible? Is this a bad design?

If possible, how do I create a new entry in the pets_users table?


You don't need a join table for this.

User has_one Pet
Pet belongs_to User

The pet table then would have a user_id column and Active Record handles the rest for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜