If I understand correctly what you need, a computer may belong to many users and one user can have many computer, right? same for phones, I assume.
In this case, the relationship is :has_and_belongs_to_many, but you do not need the classes OwnComputer and the other one. you just need two tables (without id) which will contain, for each record, a couple of id identifying one coupling (user-computer for one table, user-phone for the other). have a look at: http://wiki.rubyonrails.org/rails/pages/has_and_belongs_to_many for naming conventions. Regards, Rey9999 On 10 Feb, 15:31, James Bond <[email protected]> wrote: > I have tables: > > users (id, name) > computers (id, name) > mobiltelefons (id, name) > > OwnComputers (id, user_id, computer_id) > OwnMobiltelefons (id, user_id, mobiltelefon_id) > > So is it has_many :through or has_and_belongs_to_many or what? > > I only need to search one "own" table at time: > All computers that user "xx" owns OR > All Mobiltelefons that user "xx" owns OR > who owns mobilitefon "zz" OR > who owns computer "yy" > > So... > > class Computers < ActiveRecord::Base > has_many :OwnComputer > has_many :user, :through => :OwnComputer > end > > class OwnComputers < ActiveRecord::Base > belongs_to :Computer > belongs_to :User > end > > class Users < ActiveRecord::Base > ??? > end > > class Mobiltelefons < ActiveRecord::Base > ??? > end > > class OwnMobiltelefons < ActiveRecord::Base > ??? > end > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

