View for has_many and belongs_to but with only one associated record

Restaurant Load (1.5ms) SELECT * FROM “restaurants” INNER JOIN
“restaurant_branches” ON “restaurant_branches”.“restaurant_id” =
“restaurants”.“restaurant_id”
±---------±--------±--------±--------±---------±--------±---------±--------±--------±--------±--------±--------±--------±--------±--------±------+
| resta… | res_… | res_… | crea… | updat… | user_id | resta… | addr…
| addr… | addr… | addr… | addr… | addr… | numb… | numb… | email |
±---------±--------±--------±--------±---------±--------±---------±--------±--------±--------±--------±--------±--------±--------±--------±------+
| 27 | DOGG… | WE S… | 2014… | 2014-… | 4 | 28 | 405 …
| | CHICAGO | IL | 60666 | USA | | | |
| 27 | DOGG… | WE S… | 2014… | 2014-… | 4 | 29 | 111 …
| | CHICAGO | IL | 60661 | USA | | | |
±---------±--------±--------±--------±---------±--------±---------±--------±--------±--------±--------±--------±--------±--------±--------±------+

As you can see, I have two records for record 27. This is from a joined
table between restaurants and restaurant_branches. How would I approach
this in a view so that when I select a record on my index.html.erb file
when it gets routed to the show.html.erb file it’ll only take one row of
that record and only show me one branch instead of 2?

Thank you for any help.

Which Rails query are you using for getting the output?

On 20 July 2014 02:00, Mano S. [email protected] wrote:

| | CHICAGO | IL | 60661 | USA | | | |

±---------±--------±--------±--------±---------±--------±---------±--------±--------±--------±--------±--------±--------±--------±--------±------+

As you can see, I have two records for record 27. This is from a joined
table between restaurants and restaurant_branches. How would I approach
this in a view so that when I select a record on my index.html.erb file
when it gets routed to the show.html.erb file it’ll only take one row of
that record and only show me one branch instead of 2?

Have you checked by using count whether there are in fact two records
returned and this is not just a figment of the logging? If there are
two then also include restaurant_branches.id and I think you will find
there are in fact two branches.

Colin