On Mon, Mar 15, 2010 at 3:24 PM, Conrad Taylor <[email protected]> wrote:
> On Mon, Mar 15, 2010 at 10:07 AM, Frank Kim <[email protected]> wrote: > >> Hi everyone, >> >> I want to create a model that uses two tables for its data. Is that >> possible or just a bad idea? I don't want to do the has_one because I >> want to avoid the extra dereferencing. >> >> For example >> >> Model A >> - attributes name in first table >> - attribute phone_num in second table >> >> Thanks, >> Frank >> > > Frank, the only reason that I can see having multiple tables would be in > the following scenario: > > class User < AR > has_many :phone_numbers > end > > class PhoneNumber > belongs_to :user > end > The above should be class PhoneNumber < AR belongs_to :user end Note: AR is a shorthand for ActiveRecord::Base. -Conrad > Now, both User and PhoneNumber would have there own individual database > tables. Also, the phone_numbers table will require a foreign key (i.e. > user_id). I would recommend reading the relevant sections on associations > in "Agile Web Development with Rails 3rd" by Dave Thomas et al or consult > the guides.rubyonrails.com. > > Good luck, > > -Conrad > > >> >> -- >> >> 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 [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<rubyonrails-talk%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

