Edit/create does not work after converting habtm to has_many through

21 views
Skip to first unread message

p k

unread,
Nov 12, 2010, 10:32:51 AM11/12/10
to ActiveScaffold : Ruby on Rails plugin
I'm using Rails 2.3 and the AS plugin for the same branch (2.3). This
worked fine till now, but for reasons beyond my control, I need to
convert my existing HABTM associations to has_many through
associations.

I have made the corresponding changes (has_many through) in my
original models (say, a and b) and added a third model (a_b) for the
association table. I also added an autoincrement id column to the
association table.

The list of entries in the database for model a still show up fine
but, now when I try to edit the list of associated entries (model b)
that model a points to, the form submits fine, but does not update
anything. It shows the same original list of associated entries.

Do I need to make any other changes to get this working? Or does AS
only support HABTM associations?

Let me know if you need more info.

Thanks,
PK

Sergio Cambra .:: entreCables S.L. ::.

unread,
Nov 15, 2010, 3:30:32 AM11/15/10
to actives...@googlegroups.com

Has many through should work. Are you excluding a_b column? Is sent form data
right? You can get it in log file.

--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) ser...@entrecables.com

p k

unread,
Nov 15, 2010, 4:06:23 PM11/15/10
to ActiveScaffold : Ruby on Rails plugin
Thanks for the reply Sergio. It did point me in the right direction
where I had 'b' as one of the columns in the a_controller, instead of
a_b.

Now all updates work fine except when I remove an association between
a and b. Say I remove a value "b3" associated with "a1", in the a_b
table, the value for b_id is changed to NULL instead of deleting this
row. In other words, the association is not destroyed, but one of the
values is changed to NULL.

How do I configure this to destroy the row in the join table, rather
than storing the id as NULL?

Thanks,
PK




On Nov 15, 3:30 am, "Sergio Cambra .:: entreCables S.L. ::."

Jack Miller

unread,
Nov 15, 2010, 9:54:02 PM11/15/10
to ActiveScaffold : Ruby on Rails plugin
Adding :dependent => :destroy to your "a" has_many association should
do the trick.
Reply all
Reply to author
Forward
0 new messages