Hello, I need some help please. I have two tables: accounts ======id name accdesc_id accdescs ======id accountdescription An account can only have one accountdescription but a description can have many accounts. I have created two models: account & accdesc for account I have: has_one :accdesc and for accdesc: belongs_to :accounts Is this correct? It might be causing the other problem I have ... I want to use paginate to create a list of accounts with their type i.e do a join between the two. I thought rails did this stuff for me but I can''t get it to work. @account_pages, @accounts = paginate :accounts, :per_page => 10 How do I get to the accountdescription please? Also how do I cast an integer into a string? I have some very complex SQL I need to run out of find_by_sql and the id is held in session[''userid'']. I have googled for all the answers but I haven''t found anything. Thanks!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Elad Meidar - Creopolis.com
2007-Jan-13 09:48 UTC
Re: Joins, paginate and casting an integer to a string
Hi Jez, :account belongs_to :decription :description has_many :accounts and of course Account table must include a foreign key to the description table (Default being used is accdesc_id) integer casting: you have 3 options: 1. use interpolated string => "Elad is #{@programmer.age.to_s} years old" 2. concat strings => "Elad is " + @programmer.age.to_s + " years old" 3. when setting a condition in sql query => SuperHero.find(:first, :conditions => ["power_count = ?", @power_count_needed]. any questions, i''m on elad-JJg+wbmsuWCakBO8gow8eQ@public.gmane.org hope this helps. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---