How to invalidate has_many relationship in Rails?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

Not in their public API, but you could try the reset method on the AssociationCollection class Watching the log: s = Student. First s. Courses # Courses # courses.

Reset # No db s. Courses # .

Not in their public API, but you could try the reset method on the AssociationCollection class. Watching the log: s = Student. First s.

Courses # Courses # courses. Reset # No db s. Courses # .

This does exactly what I need. Thank you! – ChrisInEdmonton Aug 17 '10 at 15:10.

Expansion of what I couldn't say in 140 characters... You can avoid needing to invalidate relations by using some of Rails' convenience methods that are attached to an association. Let's say, for example, that I have a User and a Project model: class Project "Some Project, :description => "Some Description").

Definitely true, but if I'm updating, not creating, data, I end up iterating through the elements in the associating and calling save on each of them. With, say, 50 associated rows, that's 50 SQL statements, which is what I'm trying to get away from. Still, your example is the more common case so although it doesn't solve my problem, +1.

– ChrisInEdmonton Aug 16 '10 at 22:37.

You should have a look at the build in update_attribute methods which update via SQL but have the advantage of changing the local attributes.

That's not going to help me. Perhaps I am reading things incorrectly, though, and there's some way to call update_attribute across all rows. – ChrisInEdmonton Aug 17 '10 at 1:35.

In my Rails app, I have a class with a has_many relationship. For the sake of efficiency, I want to do some direct SQL to update many rows in the database at once, and then I want to mark the has_many relationship as no longer valid. If later code accesses the has_many relationship, I want it to reload the data.

But I obviously want to skip the SQL unless it is necessary. I may well be missing something rather obvious.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions