Forum: Ruby on Rails override << method

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.
M Daggett (Guest)
on 2006-01-12 08:03
(Received via mailing list)
Ok, this statement may prove that i am designing my app incorrectly
but I have several HABTM relationships in my application that I add to
using the <<. However, this undermines my ability to validate
uniqueness of my rows. As an example.

a = Article.find(1)

c = Comment.find(1)

a.comments << c
a.comments << c

a.comments.size
"2"

Obviously, I'd like to avoid this. Even though I have locked down the
presentaion layer so that theoretically this sort of thing would not
happen, I'd like to protect it on the model layer if possibe.

Any Ruby syntax gurus out there feel free to chime in, I am all ears.

Thanks!

Mark

--
This topic is locked and can not be replied to.