Hi, A few days ago I submitted the following ticket http://dev.rubyonrails.com/ticket/596 asking that ActiveRecord::Timestamp also apply for the join tables of habtm. The answer was that it was left for milestone 1.x, and since I think that without this functionality rails 1.0 would be incomplete, I''m raising the issue here to discuss it. My use case is very simple, I think. When I relate two objects, it woudl be very useful for me to have available the moment I did so, so that I can have a default order which is not the id of any of the tables, but the order of addition. Specifically, I''m thinking of books and owners, it would make sense to me to have the books a user bought ordered alphabetically, but would make more sense sometimes to have them in chronological order (or the order the user entered them) Any thoughts? If I''m given some directions I could try to prepare the patch myself. cheers Victor
Victor Jalencas wrote:> Hi, > > A few days ago I submitted the following ticket > > http://dev.rubyonrails.com/ticket/596 > > asking that ActiveRecord::Timestamp also apply for the join tables of > habtm. > The answer was that it was left for milestone 1.x, and since I think > that without this functionality rails 1.0 would be incomplete, I''m > raising the issue here to discuss it. > > My use case is very simple, I think. When I relate two objects, it > woudl be very useful for me to have available the moment I did so, so > that I can have a default order which is not the id of any of the > tables, but the order of addition. Specifically, I''m thinking of books > and owners, it would make sense to me to have the books a user bought > ordered alphabetically, but would make more sense sometimes to have them > in chronological order (or the order the user entered them) > > Any thoughts? If I''m given some directions I could try to prepare the > patch myself. > > cheers > VictorVictor, My best advice would be that a patch is far less likely to be pushed back than a request. So, if you''ve got the time, that''s the best way to get your changes integrated ASAP. That being said, you''ll probably want to look at the insert_record method in lib/active_record/associations/has_and_belongs_to_many.rb. The biggest problem is going to be that the created/updated timestamps are hooked into ActiveRecord classes, and there are no such classes for the join table (usually). Thus, the insert_record function is kind of "dumb" in that it doesn''t really know the schema behind the join table, and cannot tell if a created_at or updated_at column is present. You might consider passing something through with the attributes, and that would even be a good work-around to run with until you came up with something more solid. Another work around that would avoid touching all your code would be to write custom finder_sql that just adds the timestamp behind the scenes. This sounds like a decent feature if it gets implemented cleanly (just don''t try and make insert_record query the schema). I wish you luck and happy hacking :) -Scott _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Scott Barron wrote:> Victor Jalencas wrote: > >> Hi, >> >> A few days ago I submitted the following ticket >> >> http://dev.rubyonrails.com/ticket/596 >> >> asking that ActiveRecord::Timestamp also apply for the join tables of >> habtm. >> The answer was that it was left for milestone 1.x, and since I think >> that without this functionality rails 1.0 would be incomplete, I''m >> raising the issue here to discuss it. >> >> My use case is very simple, I think. When I relate two objects, it >> woudl be very useful for me to have available the moment I did so, so >> that I can have a default order which is not the id of any of the >> tables, but the order of addition. Specifically, I''m thinking of books >> and owners, it would make sense to me to have the books a user bought >> ordered alphabetically, but would make more sense sometimes to have >> them in chronological order (or the order the user entered them) >> >> Any thoughts? If I''m given some directions I could try to prepare the >> patch myself. >> >> cheers >> Victor > > > Victor, > > My best advice would be that a patch is far less likely to be pushed > back than a request. So, if you''ve got the time, that''s the best way to > get your changes integrated ASAP. > > That being said, you''ll probably want to look at the insert_record > method in lib/active_record/associations/has_and_belongs_to_many.rb. The > biggest problem is going to be that the created/updated timestamps are > hooked into ActiveRecord classes, and there are no such classes for the > join table (usually). Thus, the insert_record function is kind of > "dumb" in that it doesn''t really know the schema behind the join table, > and cannot tell if a created_at or updated_at column is present. >I may have lied to you here. Investigating further the function does access as such: columns = @owner.connection.columns(@join_table, "#{@join_table} Columns") That would be a good place to start. Sorry for the noise. -Scott _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for the input Scott. I''ll begin there victor Scott Barron wrote:> > I may have lied to you here. Investigating further the function does > access as such: > > columns = @owner.connection.columns(@join_table, "#{@join_table} Columns") > > That would be a good place to start. Sorry for the noise. > > -Scott > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Actually, I''ve begun by the unit tests. When I try to run rake test_mysql_ruby, I get: (in /home/victor/Documents/eclipse/workspace/ar) ruby1.8 -Ilib:test:test/connections/native_mysql -S testrb test/deprecated_associations_test.rb test/callbacks_test.rb test/class_inheritable_attributes_test.rb test/thread_safety_test.rb test/binary_test.rb test/mixin_test.rb test/locking_test.rb test/inheritance_test.rb test/reflection_test.rb test/associations_test.rb test/aaa_create_tables_test.rb test/lifecycle_test.rb test/multiple_db_test.rb test/unconnected_test.rb test/column_alias_test.rb test/finder_test.rb test/modules_test.rb test/transactions_test.rb test/fixtures_test.rb test/base_test.rb test/aggregations_test.rb test/pk_test.rb test/validations_test.rb /home/victor/Documents/eclipse/workspace/ar/test/../lib/active_record/base.rb:212: uninitialized constant ActiveRecord::Base::ClassInheritableAttributes (NameError) from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__'' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `require'' from /home/victor/Documents/eclipse/workspace/ar/test/../lib/active_record.rb:35 from /home/victor/Documents/eclipse/workspace/ar/test/abstract_unit.rb:5:in `require'' from /home/victor/Documents/eclipse/workspace/ar/test/abstract_unit.rb:5 from ./test/deprecated_associations_test.rb:1:in `require'' from ./test/deprecated_associations_test.rb:1 from /usr/lib/ruby/1.8/test/unit/collector/dir.rb:76:in `require'' from /usr/lib/ruby/1.8/test/unit/collector/dir.rb:76:in `collect_file'' from /usr/lib/ruby/1.8/test/unit/collector/dir.rb:62:in `recursive_collect'' from /usr/lib/ruby/1.8/test/unit/collector/dir.rb:29:in `collect'' from /usr/lib/ruby/1.8/test/unit/collector/dir.rb:28:in `each'' from /usr/lib/ruby/1.8/test/unit/collector/dir.rb:28:in `collect'' from /usr/lib/ruby/1.8/test/unit/autorunner.rb:59 from /usr/lib/ruby/1.8/test/unit/autorunner.rb:54:in `[]'' from /usr/lib/ruby/1.8/test/unit/autorunner.rb:183:in `run'' from /usr/bin/testrb:5 rake aborted! Command failed with status (1): [ruby1.8 -Ilib:test:test/connections/native_mysql -S testrb test/deprecated_associations_test.rb test/callbacks_test.rb test/class_inheritable_attributes_test.rb test/thread_safety_test.rb test/binary_test.rb test/mixin_test.rb test/locking_test.rb test/inheritance_test.rb test/reflection_test.rb test/associations_test.rb test/aaa_create_tables_test.rb test/lifecycle_test.rb test/multiple_db_test.rb test/unconnected_test.rb test/column_alias_test.rb test/finder_test.rb test/modules_test.rb test/transactions_test.rb test/fixtures_test.rb test/base_test.rb test/aggregations_test.rb test/pk_test.rb test/validations_test.rb ] I have browsed through the source, and old versions of active record, and found that Base is now missing a require (''active_record/support/class_inheritable_attributes'') that perhaps could help me here (even though the file no longer is there) What can I do to run the unit tests? I have checked out the source from svn, but only for active record. Do I need to checkout the other packages as well? victor Victor Jalencas wrote:> Thanks for the input Scott. I''ll begin there > > victor > > Scott Barron wrote: > >> >> I may have lied to you here. Investigating further the function does >> access as such: >> >> columns = @owner.connection.columns(@join_table, "#{@join_table} >> Columns") >> >> That would be a good place to start. Sorry for the noise. >> >> -Scott >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
David Heinemeier Hansson
2005-Mar-09 00:28 UTC
Re: Automatic timestamping in join tables [596]
> What can I do to run the unit tests? I have checked out the source > from svn, but only for active record. Do I need to checkout the other > packages as well?Yes. Checkout the entire trunk. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://www.loudthinking.com/ -- Broadcasting Brain
Thanks, that worked perfectly. After spending most of yesterday playing with the code, I think I might find today the way to do it... victor David Heinemeier Hansson wrote:>> What can I do to run the unit tests? I have checked out the source >> from svn, but only for active record. Do I need to checkout the other >> packages as well? > > > Yes. Checkout the entire trunk. > -- > David Heinemeier Hansson, > http://www.basecamphq.com/ -- Web-based Project Management > http://www.rubyonrails.org/ -- Web-application framework for Ruby > http://www.loudthinking.com/ -- Broadcasting Brain > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails