(or maybe you had a different model in mind when you said put the 3 FKs in a record? )
On Thu, Mar 25, 2010 at 4:43 PM, Alex Bowyer <[email protected]> wrote: > Hi Matt, > Thanks > > Yes, hard coded, this is a one time, time-specific app that won't be used > again. > > so if i just have three fields > > first_choice > second_choice > third_choice > > what do I have to do to make sure rails and hobo knows they are foreign > keys? I only know how to specify foreign keys via has_many etc > > Thanks > Alex > > > On Thu, Mar 25, 2010 at 4:40 PM, Matt Jones <[email protected]> wrote: > >> >> On Mar 25, 2010, at 3:57 PM, Alex Bowyer wrote: >> >> I have a fairly simple scenario: >>> >>> Voters (name + email address) vote on Choices (name, details, URL) >>> I want voters to be able to pick one "first choice", one "second >>> choice" and one "third choice" - their vote consists of these exactly >>> 3 selections. >>> >>> So the two questions to answer are >>> 1) what's the best way to model this >>> 2) how to create a form where the user can select these three choices >>> >>> 1) Model >>> >>> Based on what I've learnt so far, i'm thinking a link table would work >>> - voter_choices... >>> ie. >>> Voter has_many Choices :through voter_choices >>> Choices has_many Voters :through voter_choices >>> then fix it to be just 3 votes with validation >>> I was thinking then add a "rank" field to the link table and use >>> validation to ensure there is only ever one entry per user for each >>> rank (1,2,3) >>> >>> Is this the best way to model it or is there a better way? >>> >>> >> It's very dependent on the application: is the number of choices >> hard-coded? In other words, will the client come along next week and say, >> "Could you have them pick a *fourth* choice?" >> >> If first/second/third (think Olympic medals: they aren't going to add a >> "copper" medal, one presumes) aren't going to change, it might be sufficient >> to just put the 3 FKs in a record. The solution you've described is more >> flexible, but *much* more complicated. >> >> --Matt Jones >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Hobo Users" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<hobousers%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/hobousers?hl=en. >> >> > > > -- > ============================================ > Alex Bowyer > > Email: [email protected] > Skype/ooVoo: alexbowyer > > Personal blog: http://alexbowyer.blogspot.com/ > Professional blog: http://www.bitcurrent.com/ > > "The web is not a destination. It is an interface between people." > > ============================================ > -- ============================================ Alex Bowyer Email: [email protected] Skype/ooVoo: alexbowyer Personal blog: http://alexbowyer.blogspot.com/ Professional blog: http://www.bitcurrent.com/ "The web is not a destination. It is an interface between people." ============================================ -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
