I have been able to make 2 ActiveRecord tables, Profile and Bot. I have been unable to figure out how to link them properly.
There are thousands of Profiles with columns username, gender. A handful of Bots with columns botname, level
When a bot visits a profile two pieces of info need to be recorded. visited and response should be updated for that specific bot. visited is a boolean that will indicate that one particular bot has visited that one particular profile. the response is a string, again like the visited this is a response for one particular bot that was sent by one particular profile. I am thinking I need a 3rd table that joins these two tables.
I need to keep a record of every profile that every bot visits and the response that happens when it visits.
How can I create this relationship and how can I set/update the columns?
Thanks
I’m not completely certain of your requirements, so I will restate them:
I think your instincts about a join table are good. I don’t think a boolean “visited” column works, however, because if you have a record of a visit, that’s an indication that the profile was visited. If the record doesn’t exist, then it wasn’t visited.
Given this, I think your tables look like this:
To maintain the integrity of your data, you’ll want to set up foreign key constraints between this visit table and your profile and bot tables.
You’ll need to decide if it’s “legal” for a given bot to visit a particular profile more than once. If it’s not, you should put a unique constraint on the combination of profile_id and bot_id in the visit table, and catch the duplicate key errors when your DBMS throws them at you (or otherwise handle dupes.)
I hope that helps.