Displaying 20 results from an estimated 300 matches similar to: "redefining the method belongs_to in ActiveRecord::Base"
2006 Jul 16
0
Why does belongs_to handle "conflicts" this way?
When you define belongs_to in a model, you can either access
association or association_id. I was wondering how Rails would handle
things if you set each one to be different.
I made two simple models:
class Foo < ActiveRecord::Base; end
class Bar < ActiveRecord::Base
belongs_to :foo
end
Now here''s a script/console session.
>> f = Foo.create
=> #<Foo:0x270ec10
2006 Mar 13
1
adding custom cache field
Hello,
I needed to add custom cache field for one of my application. I thought I
will share the code showing how to do this.
This code below creates and maintain a custom cache field, for keeping track
of totals. Say, you have accounts, and for each account there are transactions
(either deposit/withdrawal), and one will like to keep track of the total
balance for an account.
So, let there be a
2006 Aug 16
0
acts_as_paranoid and alias_method_chain
when i require acts_as_paranoid I''m getting: undefined method
`alias_method_chain'' for #<Class:ActiveRecord::Base> (NoMethodError)
It happens in acts_as_paranoid''s init.rb. here''s the whole file. the
alias_method_chain is near the bottom. please advise.
class << ActiveRecord::Base
def belongs_to_with_deleted(association_id, options = {})
2007 Jan 28
0
problems with acts_as_paranoid (noticed while using acts_as_versioned)
hello,
I''m using the trunk versions of both plugins.
I''m running into this error when I run a migration to try and create
the versioned table for the model ''Note''
stack level too deep
/Users/Adam/dev/sweetspot/app/trunk/config/../vendor/plugins/
acts_as_paranoid/init.rb:5:in `belongs_to_without_deleted''
2005 Apr 27
4
has_many syntax
Hi all,
I have the following inside of an AR class definition:
relationships=ActiveRecord::Base.connection.select_all(my_relationships_sql)
relationships.each do |relationship|
has_many RelatedItems, :class_name => relationship[''RelatedClass''],
:foreign_key => relationship[''ForeignKey'']
end
This kind of works, but how can I assign the name of the
2012 Feb 23
1
Bug in nested_attributes_for: question about best way to patch
I''ve discovered what I''m pretty confident is unexpected behavior in
accepts_nested_attributes_for, and am developing a patch, but I''ve
encountered a question about how the core team would prefer the
implementation to look.
Here''s the bug: when assigning to a belongs_to relationship (and I
believe one-to-one, but I haven''t verified yet) if you mark the
2006 Jan 10
5
problems overriding module with plugin
Hi I am trying to create a plug-in to fix the error in the rails core
produced by the multiple delete on a HABTM relationship. I have
confirmed that my plug-in is being included into the base during
runtime however the code does not seem to be overridding the base
class.
module ActiveRecord
module Associations
module ClassMethods
def has_and_belongs_to_many(association_id, options =
2006 Jun 19
3
can''t dump anonymous class Class
I''m trying to create a document upload system, where most of the code is
the super class Document and just the path to file on the system is
controlled by the sub classes. When I attempt to use my code, I get the
following when I try to save the document.
can''t dump anonymous class Class
Any ideas?
** Migration **
class CreateDocuments < ActiveRecord::Migration
def
2006 Mar 19
0
Trouble redefining ActiveRecord default error messages
Hello,
I''m redefining ActiveRecord::Errors.default_error_messages in order
to translate ActiveRecord''s validation messages. I''m putting the
redefinition in config/environment.rb.
The trouble is that I''ve found that this approach works as long as I''m
running in development mode under WEBrick, but not on my ISP under
production mode. I guess the
2005 Oct 12
1
[ win32utils-Support Requests-2614 ] warning: redefining constant Struct::Win32ServiceStatus
Support Requests item #2614, was opened at 2005-10-12 10:23
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=412&aid=2614&group_id=85
Category: win32-service
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Scott Harper (sharperct)
Assigned to: Nobody (None)
Summary: warning: redefining constant Struct::Win32ServiceStatus
Initial
2006 Jan 27
0
Plugin - Redefining Numericality
I''ve put together another plugin, this time it adds some convenience
functions to the
validates_numericality_of validation routine. Nothing in this plugin can''t
be done with
existing validation routines, it just moves them to a place I feel is more
appropriate.
http://www.railtie.net/articles/2006/01/27/defining-numericality
PS: Sorry for hijacking threads with my
2010 Oct 01
1
undefining and redefining a Domain
<resending as I don't think I was in the mailing list yet when I sent
first time... apologies if you receive this twice>
Hello,
I'm facing some strange behavior, and I hope you can provide a
clarification.
Consider the following code:
virDomainPtr dom = virDomainLookupByName(virt, domain_name);
if (dom) {
printf("domain already
2010 Oct 12
2
Fwd: undefining and redefining a Domain from libvirt java bindings
hi,
i am trying to undefine a domain by using dm.undefine();
and then trying to create one with same name is giving me error saying
'Domain not found: no domain with matching uuid
'aeae9d4e-17cb-b661-a612-88ac677c28c1'
i have attached my test program which reproduces the issue.
please let me know where i am going wrong?
configuration: libvirt : 0.6.3
Java
2010 Jan 30
0
[LLVMdev] Redefining function
Conrado Miranda wrote:
> To implement something that is common in Lisp. Suppose I have a program
> that is running and can't be stopped or the cost being stoped is
> prohibitive. If I find a better way to run an algorithm, I'd like to
> update the running program non-stopping.
The way I do this in Pure is to always call global functions in an
indirect fashion, using an
2010 Jan 31
0
[LLVMdev] Redefining function
On Sun, Jan 31, 2010 at 7:35 AM, Conrado Miranda
<miranda.conrado at gmail.com> wrote:
> Great! It just worked. I was a bit worried about using pointers to call
> functions because it's a little too overwhelming in a big project, I think.
>
> Just for the record, if the function code isn't freed with
> freeMachineCodeForFunction, I get a segmentation fault during
>
2014 Feb 08
1
Redefining .Call
Hi All,
is there a caveat in redefining .Call in a package? (Apart from the
performance hit of the extra function call.)
I want to execute a check every time I call back to C, and this seems to be
the easiest solution, instead of modifying all functions of the package. It
also seems to be a good way to supply the PACKAGE argument, btw.
I guess this is a good solution, but I might have
2005 Sep 17
0
Reloading and redefining methods: infinite recursion
When I redefine a method like this
class Klass
alias_method :method_without_addition, :method
def method_with_addition
...
method_without_addition
...
end
alias_method :method, :method_with_addition
end
I get into trouble in the development environment. As these definitions
are executed again for each request, the second time around
method_without_addition is actually the
2015 Apr 17
3
Redefining {
I am curious if anyone knows of R code where the "{" function is
redefined in a useful way. Or "(" for that matter.
Thanks
Mick
2010 Jan 31
1
[LLVMdev] Redefining function
Hi Jeffrey,
> 2. It could compile C, and either replace B's machine code with a
> jump to C, or replace all calls to B with calls to C. Aside from not
> having the infrastructure to do this, it's not thread-safe:
> http://llvm.org/PR5184.
if all calls were via a handle (i.e. load the function pointer out of
some memory location then jump to it), then you could compile C,
2006 Jan 30
2
problem redefining module method
I''m having a problem redefining a method in one of my modules. Lets
say I have this module in /lib:
module Hello
def say_hello
"hello"
end
end
And one of my ActiveRecord models mixes it in like:
class Item < ActiveRecord::Base
include Hello
end
This works fine, I can call @item.say_hello just fine. But when I try
to redefine the method:
class Item <