-1

Question: Is there opposite of remove_all_ in Ruby Sequel

Background: I have two models (let's say car and factory ) with association between them. I am able to remove all cars from factory (factory.remove_all_cars) but in front-end user also has option to mark checkbox for associating all cars. In such case i need in my model something like factory.add_all_cars

Mailo Světel
  • 24,002
  • 5
  • 30
  • 40
  • I tried to call `.add_all_cars` and google for "ruby sequel opposite of remove_all_". Atm i have it implemented by own each block, but it does not seems to me like THE way – Mailo Světel Aug 09 '13 at 10:02

1 Answers1

1

You probably want something like:

factory.
  class.
  association_reflection(:cars).
  associated_dataset.
  all{|car| factory.add_car(car)}

The reason there is no add_all_cars method is because few people need such a feature. This is the first time I've seen a request for such a method in the more than 5 years I've been maintaining Sequel.

Jeremy Evans
  • 11,959
  • 27
  • 26