Has and Belongs to Many question

1 view
Skip to first unread message

Mayank Sharma

unread,
Nov 7, 2009, 10:36:38 AM11/7/09
to bangal...@googlegroups.com
Hi,

I am trying to store a list of interconnected graph nodes using active records in rails. For this I am using Has and Belongs to Many association for my node. The problem is that in the join table I wish to store the weight of the edge between the two nodes as well. That in itself is not an issue as I can add an extra column in the join table. But how do I access (read/write) this column from my nodes model?

Any good ideas?

-Mayank

Amit Mathur

unread,
Nov 7, 2009, 1:20:23 PM11/7/09
to bangal...@googlegroups.com
Hi Mayank,

In general, if you need to put attributes on the join table, i.e. want to make join table a model, you should use has_many :through associations in place of HABTM.

HTH.

Regards,
Amit.

Mayank Sharma

unread,
Nov 7, 2009, 2:57:51 PM11/7/09
to bangal...@googlegroups.com
Thanks Amit, got it working. amazed by how simple the solution was. I was not thinking beyond HABTM

-Mayank
Reply all
Reply to author
Forward
0 new messages