Thanks. I am sure it is something I am missing. I am trying to learn
about SQL and Rails.
Here is the script I am using. I am really just trying to create a
script that explores all of the database relationships and how to
implement them in Rails.
I believe it’s because the << method both append the specified object
to the collection (in your case, a Category to a Products categories
collection) AND saves it afterwards. So saving the product twice might
cause the category to be added twice. At least that’s what I think. So
in your case I’ld do like this:
Thanks David, I poked around in the debugger a bit after your
suggestion, and honestly, I don’t understand Ruby code well enough to
make sense of it all. Not to mention, I kept running into
No sourcefile available for (eval)
However, what I did find was that the << operator, did not issue the
insert command in the “double” case. The save command after the fact
seemed to issue the two inserts. Now this confuses me completely.
So, if anyone can explain why/how this could happen, that would be
great.
Thanks. I am sure it is something I am missing. I am trying to learn
about SQL and Rails.
Here is the script I am using. I am really just trying to create a
script that explores all of the database relationships and how to
implement them in Rails.
RAFB apparently drops files after 24 hours - any chance you could put
those examples up someplace (gist or pastie, for instance) with a
little more persistence?
Without seeing the code, it’s hard to even guess what’s going on. But
I seem to recall seeing similar behavior when I had code saving an
associated record in before_save, which then got picked up again by
the association save callbacks.
RAFB apparently drops files after 24 hours - any chance you could put
those examples up someplace (gist or pastie, for instance) with a
little more persistence?
Without seeing the code, it’s hard to even guess what’s going on. But
I seem to recall seeing similar behavior when I had code saving an
associated record in before_save, which then got picked up again by
the association save callbacks.
I totally agree. Ball, you should really paste some code somewhere, so
we can try to figure out what’s wrong here.