Displaying 20 results from an estimated 100 matches similar to: "adding action after a belongs_to assignment"
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
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!
2006 May 02
0
Self-referential MtoM implementation
ok, guys i have followed the self referential recipe from the book it
works perfect but now i have some doubts, at the end the model are
modified to force the user beign added as a friend that add too who are
adding him so how i can make that the full relationship doesn?t be
complete until the friend beign added approves it(talking in the
implementation of the code of course)?
by the way,
2006 Apr 17
0
Pros/cons of doubling up in Self-Referential has_many via :through
Relative newbie so would welcome comments re structure of a
self-referential relationship I''ve got.
It''s started off similar to the Person HABTM friends in the Rails
recipes books (working fine), but I needed to turn the join table into a
full-blown model as I wanted to add attributes to it. Few tricky bits
dealing with the new :through structure and understanding how :scope
2007 Feb 05
0
after_save and associations
It appears that when after_save is triggered, associations such as
habtm haven''t been populated yet.
Each association can have an :after_add callback, but my code needs to
access multiple associations.
Is there an explicit reason why after_save isn''t triggered after all
of the associations have been populated?
--~--~---------~--~----~------------~-------~--~----~
You received
2012 Jun 01
0
Association callbacks on model observers
Hello all first post so be kind,
Is there a way to use association callbacks on model observers? For
instance if I have a has_and_belongs_to_many association on my model I can
add a private method for instance to be called on the :after_add, is there
a way to move this to an observer I have created for this model?
Thanks
.FxN
--
You received this message because you are subscribed to the
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
2013 Sep 13
1
log-log link function
Hi to every body. I would like assistance on how to implement the log-log
link function for binary response. Is there any package that implements it?
Many thanks
Endy
[[alternative HTML version deleted]]
2008 Feb 21
7
looping through a list
what is the proper way to loop through a list in a rails view (assuming
that you need to check if it is empty or not)
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
2013 Apr 23
1
Hosmer Lemeshow test
Hi to everybody. I use the following routine (i found it in the internet)
to compute the Hosmer-Lemeshow test in the framework of logistic regression.
hosmerlemeshow = function(obj, g=10) {
# first, check to see if we fed in the right kind of object
stopifnot(family(obj)$family=="binomial" && family(obj)$link=="logit")
y = obj$model[[1]]
# the double bracket
2014 Apr 14
1
I can't programe routine comp()
Dear R users.
I am trying to program the comp() routine in package survMisc.
I am reading the data below with d=read.table( "C:\\. . .",fill=TRUE,header=TRUE)
Then I load the packages 'survival' and 'survMisc', library(survival), library(survMisc)
and I run
2013 Apr 14
5
Logistic regression
I have a data set to be analyzed using to binary logistic regression. The
data set is iin grouped form. My question is: how I can compute
Hosmer-Lemeshow test and measures like sensitivity and specificity? Any
suggestion will be greatly appreciated.
Thank you
Endy
[[alternative HTML version deleted]]
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
2006 Jan 31
2
How can I overwrite the parent.children.push(child) Method?
Hi all
I want to overwrite the push method (which is an alias of <<, the same
as concat) of collections, and there I want to test if :uniq is set to
true in the relationship. If so, the method should check if the passed
object is already related to the parent, or not (only then it will be
added).
But I just can''t find the original code of this method, so I could
overwrite
2008 Dec 16
1
Callback when objects connect as a habtm relationship
If Product and Category models are in a habtm relationship, i.e.
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end
I want a piece of code to be executed every time a product is connected to a
category.
Where do I put this code? Which callback (and on which model) will be
triggered?
Any
2011 Aug 12
1
Getting nil value when setting an on Join model via a has_many :through relationship
Hi All,
I''ve been trying to figure out what''s wrong here for a little over a
day and figured i''d reach out to the ROR list.
A pastie explains the code a bit better than directly in email:
http://pastie.org/private/mvu0zr1xm18bsk6nfbyama
Basically i have an Artist, and he has many Songs through a join model
called Releases. An artist can be "featured" on a
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
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 =>