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 -- -------------------------------------------------------------------- I am Mark Daggett and I approve this message.
On Jan 10, 2006, at 12:07 PM, M Daggett wrote:> 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 >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 Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra@yakima-herald.com
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 Zygmuntowicz <ezra@yakima-herald.com> wrote:> > On Jan 10, 2006, at 12:07 PM, M Daggett wrote: > > > 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 > > > > 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 Zygmuntowicz > Yakima Herald-Republic > WebMaster > http://yakimaherald.com > 509-577-7732 > ezra@yakima-herald.com > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------------------------------------------------------------- I am Mark Daggett and I approve this message.
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:> 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 Zygmuntowicz <ezra@yakima-herald.com> wrote: >> >> On Jan 10, 2006, at 12:07 PM, M Daggett wrote: >> >>> 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 >>> >> >> 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 Zygmuntowicz >> Yakima Herald-Republic >> WebMaster >> http://yakimaherald.com >> 509-577-7732 >> ezra@yakima-herald.com >> >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > > -------------------------------------------------------------------- > I am Mark Daggett and I approve this message. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra@yakima-herald.com 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 Zygmuntowicz <ezra@yakimaherald.com> wrote:> 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: > > > 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 Zygmuntowicz <ezra@yakima-herald.com> wrote: > >> > >> On Jan 10, 2006, at 12:07 PM, M Daggett wrote: > >> > >>> 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 > >>> > >> > >> 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 Zygmuntowicz > >> Yakima Herald-Republic > >> WebMaster > >> http://yakimaherald.com > >> 509-577-7732 > >> ezra@yakima-herald.com > >> > >> > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > -- > > > > -------------------------------------------------------------------- > > I am Mark Daggett and I approve this message. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -Ezra Zygmuntowicz > WebMaster > Yakima Herald-Republic Newspaper > ezra@yakima-herald.com > 509-577-7732 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------------------------------------------------------------- I am Mark Daggett and I approve this message.
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:> 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 Zygmuntowicz <ezra@yakimaherald.com> wrote: >> 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: >> >>> 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 Zygmuntowicz <ezra@yakima-herald.com> wrote: >>>> >>>> On Jan 10, 2006, at 12:07 PM, M Daggett wrote: >>>> >>>>> 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 >>>>> >>>> >>>> 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 Zygmuntowicz >>>> Yakima Herald-Republic >>>> WebMaster >>>> http://yakimaherald.com >>>> 509-577-7732 >>>> ezra@yakima-herald.com >>>> >>>> >>>> >>>> _______________________________________________ >>>> Rails mailing list >>>> Rails@lists.rubyonrails.org >>>> http://lists.rubyonrails.org/mailman/listinfo/rails >>>> >>> >>> >>> -- >>> >>> -------------------------------------------------------------------- >>> I am Mark Daggett and I approve this message. >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> >> -Ezra Zygmuntowicz >> WebMaster >> Yakima Herald-Republic Newspaper >> ezra@yakima-herald.com >> 509-577-7732 >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > > -------------------------------------------------------------------- > I am Mark Daggett and I approve this message. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra@yakima-herald.com