Forum: Ruby on Rails Many to Many relationship - trys to destroy twice??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D302c032dbfd53f6be5ade7a16b1e6d1?d=identicon&s=25 Neale Yates (oznog)
on 2006-01-02 12:34
I'm trying to work with a many to many relationship but since my join
table need additional attributes I can't use habtm.

When I attempt to destroy an item from the join table RoR appears to
attempt to destroy the item twice.  Here is an example from the log file
showing the process.  The record is identified using a find_by_sql using
the two id parameters (and a third 'position' parameter for safety).
The item is then apparently sucessfully destroyed, and the controller
redirects to 'show_p'.  Then it all goes wrong, and it appears to try to
find the same record again.

Has anyone seen this before?

cheers

Neale

Processing AdminController#delete_i (for 127.0.0.1 at 2006-01-02
22:14:12) [POST]
  Parameters: {"pid"=>"2", "commit"=>"Delete", "action"=>"delete_i",
"controller"=>"admin", "ingredient"=>{"ingredient_id"=>"64",
"position"=>"8"}}
  Ingredients_Product Load (0.002288)   SELECT * FROM
ingredients_products WHERE (product_id = '2' and ingredient_id = '64'
and position = '8') LIMIT 1
  SQL (0.000563)   BEGIN
  Ingredients_Product Columns (0.013075)   SHOW FIELDS FROM
ingredients_products
  Ingredients_Product Destroy (0.002416)    DELETE FROM
ingredients_products
 WHERE id = 50

  SQL (0.001618)   COMMIT
Redirected to http://localhost:3000show_p
Completed in 0.02861 (34 reqs/sec) | DB: 0.01996 (69%) | 302 Found
[http://localhost/admin/delete_i?pid=2]


Processing AdminController#delete_i (for 127.0.0.1 at 2006-01-02
22:14:12) [POST]
  Parameters: {"pid"=>"2", "commit"=>"Delete", "action"=>"delete_i",
"controller"=>"admin", "ingredient"=>{"ingredient_id"=>"64",
"position"=>"8"}}
  Ingredients_Product Load (0.004203)   SELECT * FROM
ingredients_products WHERE (product_id = '2' and ingredient_id = '64'
and position = '8') LIMIT 1


NoMethodError (You have a nil object when you didn't expect it!
This topic is locked and can not be replied to.