N:N association

Hello everybody,

I would like to configure this configuration:

clients

id
name
city

products

id
name
price

clients_products

client_id
product_id
date
ip_address

…But I am not sure about this following config because
clients_products table had “date” and “ip_address” attributs. Do you
think I need to build a model for clients_products able?

class Client < ActiveRecord::Base
has_and_belongs_to°many :products
end

class Product < ActiveRecord::Base
has_and_belongs_to°many :clients
end

Thanks

Hi,

The habtm relationship doesn´t work when the inner table has other
data then the id’s.

So you will need a model for it and then you’ll need the has_many
:through for having clients at products and vice-versa.

On Sun, May 4, 2008 at 1:01 PM, David B.
[email protected] wrote:

client_id
class Client < ActiveRecord::Base
Posted via http://www.ruby-forum.com/.


Rafael Gaspar - [email protected]
http://www.eucomomaca.com

Hum, okay… Thank you :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs