The image above describes the results I want, but here's a more graphical explanation.
I click one of the debates on my site <https://lh6.googleusercontent.com/-XC1TqwlaXqg/UFwPKbOM-hI/AAAAAAAAAaM/CoKYmTi5pzM/s1600/debates+1.png> And click one of the voting buttons which creates a vote in the database <https://lh5.googleusercontent.com/-WOib-PBL_xs/UFwPZxANscI/AAAAAAAAAaU/tQzUIToa2yA/s1600/debate+2.png> And that creates a row in the votes database I want to match up those votes with the comments that are made as well. <https://lh4.googleusercontent.com/-Nd0_xkbBxK8/UFwP8iEZwdI/AAAAAAAAAac/-uXTPELizI4/s1600/debate+3.png> But you can only make a comment for the stance you chose. I need to link up the posts table and the votes table, as follows. <https://lh5.googleusercontent.com/-B2YKfSDjh9Q/UFwQLVXr34I/AAAAAAAAAak/_I-k84OFeAM/s1600/how+to+join.png> My database schema is here. https://gist.github.com/8bd11534bb7cf0614fc6 On Friday, September 21, 2012 2:24:03 AM UTC+1, Jeremy Evans wrote: > > On Thursday, September 20, 2012 4:10:38 PM UTC-7, desbest wrote: >> >> >> <https://lh3.googleusercontent.com/-HxosViCEKP0/UFube_sMzeI/AAAAAAAAAZ8/UtVTCiWO7AQ/s1600/how+to+join.png> >> >> >> *When I use* >> >>> Post.where(:debate_id => view, :nodeview => 'status', :floor => >>> 0).join(:votes, :id=>:nodeview_id).join(:votes, :debate_id) >>> >> I get this error. >> >>> SQLite3::SQLException: ambiguous column name: debate_id >> >> > You get this because, surprise surpise, the column name is ambiguous. > Does it refer to the column in the posts table or the column in the votes > table? Not to mention you appear to be joining to the votes table twice > without aliasing it. > > >> >> *When I use * >> >>> @approval = Vote.where(:nodeview => 'debate', :content => >>> 'accept').join(:debates, :id=>:nodeview_id) >>> >> >> I have #{@approval[:content]} coming up blank, and #{@approval[:id]} >> being ambiguous. >> > > The id column is probably in both tables. You need to disambiguate it, > probably by aliasing the column in SELECT. > > >> Please help! >> > > Please post your database schema and describe the results you want. It's > clear that your current code is wrong, but I'm not even sure what code > would be right, since I don't know what you want. > > Jeremy > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/H7evNIRgR_UJ. 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/sequel-talk?hl=en.
