Displaying 11 results from an estimated 11 matches for "association_id".
2006 Mar 13
1
adding custom cache field
...low is tested with edge rail, and will work for polymorphic
associations also.
Any comments are welcome.
module ActiveRecord
module Associations # :nodoc:
def self.append_features(base)
super
base.extend(ClassMethods)
end
module ClassMethods
def belongs_to_extra(association_id, options = { })
association_type = association_id.to_s + "_type" if association_id
association_primary_key = association_id.to_s + "_id"
if options[:total_cache]
module_eval(
"after_create ''#{association_type}...
2006 Aug 16
0
acts_as_paranoid and alias_method_chain
...od
`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 = {})
with_deleted = options.delete :with_deleted
returning belongs_to_without_deleted(association_id, options) do
if with_deleted
reflection = reflect_on_association(association_id)
association_accessor_methods(reflection,
Caboose::Acts::Bel...
2007 Jan 28
0
problems with acts_as_paranoid (noticed while using acts_as_versioned)
...'
/Users/Adam/dev/sweetspot/app/trunk/config/../app/models/note.rb:2
All note.rb contains is this:
class Note < ActiveRecord::Base
acts_as_versioned
end
looking at the code in acts_as_paranoid, I can''t figure out why it is
getting stuck in a loop:
def belongs_to_with_deleted(association_id, options = {})
with_deleted = options.delete :with_deleted
returning belongs_to_without_deleted(association_id, options) do
if with_deleted
reflection = reflect_on_association(association_id)
association_accessor_methods(reflection,
Caboose::Acts::BelongsTo...
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:0x27...
2005 Apr 27
4
has_many syntax
...can I assign the name of the relationships?
my_relationships_sql retrieves a field called "RelationshipName", and what I
would like to do is something like this:
relationships=ActiveRecord::Base.connection.select_all(my_relationships_sql)
relationships.each do |relationship|
has_many :association_id => relationship[''RelationshipName''], :class_name
=> relationship[''RelatedClass''], :foreign_key => relationship[''ForeignKey'']
end
But that doesn''t work. Is this possible?
Adelle.
2006 Nov 09
2
redefining the method belongs_to in ActiveRecord::Base
...successful. The error message in Webrick was
> Booting WEBrick...
./script/../config/../lib/ActiveRecordExtensions.rb:67: undefined
method `belongs_to'' for module `ActiveRecord'' (NameError)
The code with problem is:
alias :attachment_belongs_to :belongs_to
def belongs_to(association_id, options={})
self.attachment_belongs_to(association_id,options)
if association_id == :attachment
code = <<EOS
alias :tmp_attach= :attachment=
def attachment=(content)
if content.class.name == ''Attachment'' #old functionality
self.tmp_attach=(conten...
2006 Jan 10
5
problems overriding module with plugin
...duced 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 = {}, &extension)
.............
code
............
end
end
end
end
this is what i have in my vendor/plugins/patches/lib directory, does
anyone know why this is not working?
Thanks,
Mark
--
---------------------------------------------------------...
2012 Feb 23
1
Bug in nested_attributes_for: question about best way to patch
...e
association for destruction the association is not unset yet the
record is deleted. This result in both unexpected behavior: the
association seems to still be present in memory after the update, and
in invalid data being saved (foreign key violations) because the
parent record saved still has the association_id set even though the
associated record has been destroyed.
Here is a test demonstrating the error and the expectations:
def
test_should_destroy_an_existing_record_if_there_is_a_matching_id_and_destroy_is_truthy
@ship.pirate.destroy
[1, ''1'', true, ''true''].eac...
2006 Feb 28
1
Cache Magic field for totaling
Hello,
Rails provide counter cache field for associations, I want a similar cache
for totaling up values
(say account_balance = sum_of_deposits - sum_of_withdrawals).
I was wondering if rails, already has another surprise in store for me, or is
there any plug-in or how-to for doing these kind of things.
Thanks.
--
Surendra Singhi
http://ssinghi.kreeti.com, http://www.kreeti.com
Read the
2006 Jan 17
15
legacy database and finder_sql nightmare!
This is my first rails app with a legacy database and I''m having a
terrible time getting the models set up correctly. I have an order
table that has a primary field named order_number. I have a name table
with a primary of item_number. These two tables are liked by the
item_number and the order_number, but not as you might think. If the
order_number is 2500, then each entry in
2006 Jun 19
3
can''t dump anonymous class Class
...le :documents do |t|
t.column :type, :string
t.column :name, :string
t.column :file_path, :string
t.column :content_type, :string
t.column :created_on, :timestamp
# attributes for type="AssociationDocument"
t.column :association_id, :integer
# attributes for type="LocationDocument"
t.column :location_id, :integer
end
end
def self.down
drop_table :documents
end
end
** Models **
class Document < ActiveRecord::Base
attr_accessor :uploaded_file
def after_create
if !File.exist...