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 = {},
&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
–
On Jan 10, 2006, at 12:07 PM, M Daggett wrote:
&extension)
anyone know why this is not working?
Thanks,
Mark
Mark-
It looks like you are on the right track but you still need the
self.included part. The basic pattern for this as I know it is like so:
module EZ
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def something(*args, &block)
end
end
end
Then in your init.rb file you would do this:
ActiveRecord::Base.send :include, EZ
Of course alter that for wherever you are trying to get your module
included into.
Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
[email protected]
Hi Ezra,
I was unsucessful in getting your suggestions to work. Here is what my
files look like. I picked a small patch the fact that you need to tell
mysql to ignore foreign key when loading and unloading the fixture
when running tests.
my plug-in looks like this:
module MysqlIgnoreForeignKeysOnFixtureLoading
def self.included(base)
base.extend(Fixtures)
end
module Fixtures
def delete_existing_fixtures
# @connection.delete “DELETE FROM #{@table_name}”, ‘Fixture
Delete’
# Deactivate foreign keys with MySQL to prevent errors when
clearing tables
# with self referencing foreign keys.
if @connection.kind_of?
ActiveRecord::ConnectionAdapters::MysqlAdapter
@connection.update “SET FOREIGN_KEY_CHECKS = 0”, ‘Fixtures
deactivate foreign key checks.’;
@connection.update “DELETE FROM #{@table_name}”, ‘Fixture
Delete’;
@connection.update “SET FOREIGN_KEY_CHECKS = 1”, ‘Fixtures
activate foreign key checks.’;
else
@connection.delete “DELETE FROM #{@table_name}”, ‘Fixture
Delete’
end
end
end
end
My init file looks like so:
require ‘mysql_adapter_patches’
ActiveRecord::Base.send :include, MysqlIgnoreForeignKeysOnFixtureLoading
when I run rake it blows up on all the foreign keys so I know that it
is not picking up the errors. Do you see something wrong with the
syntax?
Thanks,
Mark
On 1/10/06, Ezra Z. [email protected] wrote:
module Associations
self.included part. The basic pattern for this as I know it is like so:
Cheers-
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
Mark-
It looks ok to me. Although I am not sure if AR::Base is the right
place to include the module. What class are you trying to extend
specifically? Also have a look at the plugins page on the wiki. It
has a plugin that will apply patches for you that might help.
Cheers-
-EZra
On Jan 10, 2006, at 5:05 PM, M Daggett wrote:
base.extend(Fixtures)
@connection.update "SET FOREIGN_KEY_CHECKS = 0", 'Fixtures
end
end
def something(*args, &block)
Of course alter that for wherever you are trying to get
509-577-7732
–
I am Mark Daggett and I approve this message.
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732
Hi EZra,
Thanks for writing back.
I looked around in the plug-in directory but could not find
specifically any plug-in that facilitates the patching of the rail’s
core. Do you have a name of said plug-in?
In regards to the plug-in that I am trying to write, I would like to
patch:
ActiveRecord/fixtures.rb
And
ActiveRecord/associations.rb
I am not too sure how that plays out in the code-base in terms of
inheritance etc.
Any help greatly appreciated.
Best,
Mark
On 1/10/06, Ezra Z. [email protected] wrote:
On Jan 10, 2006, at 5:05 PM, M Daggett wrote:
def self.included(base)
ActiveRecord::ConnectionAdapters::MysqlAdapter
end
class.
end
Mark-
module ClassMethods
http://yakimaherald.com
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
Mark-
It looks like that plugin isn't on the plugins page anymore. Not
sure why. I think your best bet would be to find a few plugins and
look at the way they work to get themselves included into the right
place. I am not sure what exactly you want to extend so I don’t know
what to tell you at this point.
Cheers-
-Ezra
On Jan 11, 2006, at 10:11 PM, M Daggett wrote:
-EZra
# Deactivate foreign keys with MySQL to prevent errors when
else
Thanks,
Hi I am trying to create a plug-in to fix the error in the rails
&extension)
does
like so:
I am Mark Daggett and I approve this message.
509-577-7732
I am Mark Daggett and I approve this message.
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
[email protected]