Deleting items in m:n relation

Hi,

I have a m:n relation between two objects ‘order’ and ‘book’ with the
fact that one order might contain several books with the same id (e.g.
book 1 belongs twice to the order 2).

Now I want to delete one example of book 1 from order 2 such that at the
end, the order 2 has only stored one example of book 1. Unfortunately,
order.delete book always deletes all books with the corresponding id. Is
there a way to delete only the first occurring item?

Thanks in advance :slight_smile:

EtecMan wrote:

Hi,

I have a m:n relation between two objects ‘order’ and ‘book’ with the
fact that one order might contain several books with the same id (e.g.
book 1 belongs twice to the order 2).

Now I want to delete one example of book 1 from order 2 such that at the
end, the order 2 has only stored one example of book 1. Unfortunately,
order.delete book always deletes all books with the corresponding id. Is
there a way to delete only the first occurring item?

Thanks in advance :slight_smile:

You may have some luck by making use of the manual delete methods

such as Order.delete(params[:id])
or Order.delete([1,2,3])