search for: after_remove

Displaying 11 results from an estimated 11 matches for "after_remove".

2010 Jul 14
1
ActiveRecord::Observer, update_all and has_many
Hi, I''m using an ActiveRecord::Observer to log users changing data in my application. However, I''ve noted that adding an item to a has_many relationship gets logged, but removing the item does not. That is: @product.users << user is logged, but: @product.users.delete(user) is not. I''ve dug into ActiveRecord and found that the underlying issue is that the
2006 May 02
0
Self-referential MtoM implementation
...ctiveRecord::Base has_and_belongs_to_many :friends, :class_name => "Person", :join_table => "friends_people", :association_foreign_key => "friend_id", :foreign_key => "person_id", :after_add => :be_friendly_to_friend, :after_remove => :no_more_mr_nice_guy def be_friendly_to_friend(friend) friend.friends << self unless friend.friends.include?(self) end def no_more_mr_nice_guy(friend) friend.friends.delete(self) rescue nil end end -- Posted via http://www.ruby-forum.com/.
2006 Apr 17
0
Pros/cons of doubling up in Self-Referential has_many via :through
...- i.e. if person A has a relationship (of type i) with person B, then person B has a relationship (of type i) with person A. In Rails Recipes (and in my original HABTM setup), this was done by automatically adding a reverse row to the relationships table using :after_add (and removing it with :after_remove). Downside is that if the table has attributes (relationship_type, notes on relationship) this starts to get a bit messy, meaning that every time one is updated the reverse must be too. I could wrap this up in a transaction, but somehow it seems a bit inelegant. The other way -- which is how I...
2006 Apr 30
1
Callbacks on has_many relation
Hello, Is there a way to implement a callback for somehting like before_add and after_ad on a statement like this with a has_many relation? x.children << Item.create(:title=>"test") I want that x has a callback that is called when the item is added. I found something in
2010 Jul 12
1
How to turn :before_add exceptions into validation errors
As per http://rails.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html Possible callbacks are: before_add, after_add, before_remove and after_remove. Should any of the before_add callbacks throw an exception, the object does not get added to the collection. Same with the before_remove callbacks; if an exception is thrown the object doesn‘t get removed. However, when the add fails due to a before_add violation, the exception thrown just blows...
2007 Jul 21
3
unable to get "has_many :after_add" to work - need help
Can someone tell me what I''m doing wrong? I''ve spent way too much time on this -------------------------------------------------------------------------------------- class Picture < ActiveRecord::Base has_many :ratings, :after_add => :increment_rating, :after_remove => :decrement_rating def increment_members(rating) self.rating += rating.amount save! end end -------------------------------------------------------------------------------------- class Rating < ActiveRecord::Base belongs_to :picture end -------------------------------------...
2006 Oct 31
5
conditional boost? friends to come up at top of search...
Hey guys, im trying to get my friends to come up at the top of the act as ferret search. I would query the whole result set first, then move my friends to the top, but the thing is, Im paginating my results and use the offset and limit parameters in the multi_search() function. Anyone know how to do this? Thanks in advance... -- Posted via http://www.ruby-forum.com/.
2006 May 22
3
STI, HABTM & counter_cache
Hello world... I have an interesting issue that the online docs aren''t helping me with. In my app I have 4 models Item < ActiveRecord Deal < Item Product < Item Category < ActiveRecord Item has_and_belongs_to_many :categories... On each category record I''d like to maintain a product_count and deal_count to increase performance. This doesn''t appear
2006 Feb 27
4
2 belongs_to to the same parent table
Hello! I have 2 table: users and buddies User: id, name, ... Buddy: id, user_id, user_buddy_id, ... So if you have 2 users 1,jack and 2,fred and fred is a buddy of jack, there is a Buddy object: id=1, user_id=1, user_buddy_id=2 I can declare only one belongs_to in Buddy and one has_many in User. And there is conflict if I had the second one (the first one is discarded) class User has_many
2007 Sep 07
5
enforce mutual exclusivity
Hi, First post, please be gentle! I couldn''t find any mention of this already I''m using ActiveRecord and I want to enforce mutual exclusivity on a has_and_belongs_to_many. A concrete example: I have a User which can have one or more Roles (student, tutor, headmaster, administrator etc). However if a user is a student they cannot hold any other role. I was hoping to find
2006 Jan 09
6
has_and_belongs_to_many :self
Hi all I got the following class: class Member < ActiveRecord::Base has_and_belongs_to_many :buddies, :class_name => ''Member'', :join_table => ''members_have_buddies'', :foreign_key => ''member_id'', :association_foreign_key =>