Wednesday, 15 August 2012

activerecord - How to properly structure relationship from pre-established choices (or new if not exists) in rails? -



activerecord - How to properly structure relationship from pre-established choices (or new if not exists) in rails? -

this quick , simple question of thinking database. have user model , hotel model.

each user has hotel , can select 1 of hotels table or add together hotel name , address if hotel not found on table. best way that? don't want users able create hotels. thought was:

1- users table -- user.hotel-name -- user.hotel-address

2- hotels table -- hotel.name -- hotel.address

if user selects existing hotel, "copy" info hotel. not seem correct. help?

thanks

the best way , normalizing de database create table hotelusers including hotels created users.

you check if hotel exist in hotel table. next check if hotel exists in hotelusers de id of user. create new hoteluser re-create of hotel or new user

hotelusers userid name address

another way

you can have relationship many many in users <-> hotel , store 1 parameter on hotel table knowing when hotel create user.

ruby-on-rails activerecord

No comments:

Post a Comment