I’m modelling a scenario with Users and Tools, where a Tool is owned by one User but can be used by many Users including to one owning it.
I was thinking about adding an owner_id column to Tools and say it has_many Users or by adding a new relationsship table.
I’m really new to Rails and I have problems setting up the right associations in the models though, maybe you can point me in the right direction?
Thank you very much.
Your should add
owner_idto theToolstable.Associations will be like that.
You’ll need a
tools_userstable in order to use habtm-association. Generate a migration and create a table with optionid: falseand two columnsuser_idandtool_id:After that you can call something like
@user.toolsor@user.ownerRead more there