Active Record Associations

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

Rey9999 wrote:

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.

Yes

In this case, the relationship is :has_and_belongs_to_many, but you do

How can I find all users whose name is "James%" and their computers (not mobiles)?

User.find(:all, ???)

How can I find all users whose name is "James%" and their computers (not mobiles)?

User.find(:all, ???)

Help ???

Or use has_many :through instead.

Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/

Oh by the way if you do that you'll end up with an array of arrays.
Might not be what you want.

Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/

Why is a good question here. In other words, what are you going to do
with the computers and users once You get them.

Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/