zdennis / ar-extensions Goto Github PK
View Code? Open in Web Editor NEWActiveRecord::Extension (aka ar-extensions) is a plugin to extend and enhance the functionality of ActiveRecord
Home Page: http://www.continuousthinking.com/tags/arext
ActiveRecord::Extension (aka ar-extensions) is a plugin to extend and enhance the functionality of ActiveRecord
Home Page: http://www.continuousthinking.com/tags/arext
When using ar-extensions 0.9.2 with Rails 2.3.4 on ruby 1.8.6-1.8.7, the warning "default `to_a' will be obsolete" is often printed to STDERR.
The patch at [1] fixes this problem, please have a look.
[1] http://github.com/thillerson/ar-extensions/commit/fc0cab906ebc3766f22ab55e8e38a1c173187dbb
Regards
/Laust Rud
I'm using rails 2.3.2 with ar-extensions 0.9.2 (MySQL version: 5.0.75-0ubuntu10.3 (Ubuntu))
I'm trying to use the import() method on my AR models, and it works but it still run a single insert query for each record. It's very wired my models call supports_import? always return false.
When I faked that method, it raises an error undefined method 'sql_for_on_duplicate_key_update'.
Can you explain how to insert bulk records?
Thanks
The following call to sanitize_sql_from_hash yields invalid conditions:
sanitize_sql_from_hash({'state_id' => 3, 'county_id' => nil})
And ends up throwing:
wrong number of bind variables (1 for 2)
There seems to be a specific check to make sure nil is not appended to the values array, which doesn't seem right, but I don't pretend to fully understand this method so it's likely I'm missing something. Seems like the following diff would take care of it:
diff --git a/ar-extensions/lib/ar-extensions/finders.rb b/ar-extensions/lib/ar-extensions/finders.rb index 874ba3c..374ac2a 100644 --- a/ar-extensions/lib/ar-extensions/finders.rb +++ b/ar-extensions/lib/ar-extensions/finders.rb @@ -63,7 +63,7 @@ class ActiveRecord::Base result = ActiveRecord::Extensions.process( key, val, self ) if result conditions << result.sql - values.push( result.value ) unless result.value.nil? + values.push( result.value ) else # Extract table name from qualified attribute names. attr = key.to_s @@ -91,4 +91,4 @@ class ActiveRecord::Base end end -end \ No newline at end of file +end
In my Gemfile I have:
gem 'rails', '3.1.0' gem 'ar-extensions', :git => "git://github.com/zdennis/ar-extensions.git"
When I do bundle install
I get:
Bundler could not find compatible versions for gem "activerecord": In Gemfile: ar-extensions (>= 0) ruby depends on activerecord (~> 2.1) ruby rails (= 3.1.0) ruby depends on activerecord (3.1.0)
Am I missing something or is the gem really not compatible with activerecord 3.1.0? Has anyone had success using rails 3.1.0/ruby 1.9.3 with this gem? I was using it with rails 3.0.9/ruby 1.8.7 and everything was fine.
I have this issue when trying to create a new record. I'm using rails 2.3.4
columns = [:libelle]
=> [:libelle]
values = ["russe"]
=> ["russe"]
Langue.import columns, values
TypeError: can't convert Time into String
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:in<<' from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:in
add_special_rails_stamps'
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:ineach' from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:in
add_special_rails_stamps'
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:311:ineach_pair' from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:311:in
add_special_rails_stamps'
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:205:in `import'
from (irb):7
any ideas ?
You could mention in your README that PostgreSQL isn't supported for your import function.
In rails 2.3.3 they added a second parameter to sanitize_sql(). You can now pass the table_name as an option.
I'm no rdoc whiz, but ar-extensions appears to have no good documentation and then, right there in the code is a big hunk o' rdoc love! What's going on?
i want to ar -ext with seamless_database_pool plug-in but as SDP overwrite the mysql adaptor, am not able to get working ar-ext with SDP. for now i just created the new class in adaptor folder and copied the mysql adaptor and thats also working. pls replay whether this is correct or there is another sol on this.
thanks
Hello,
I am using the compositeprimarykeys gem and I am getting a error when I try to save a record with the LOW_PRIORTY keyword:
s = SurveyInfo.find_by_Client "Test Client"
=> #<SurveyInfo Client_Survey_Information_ID: 148, Client: "Test Client", Client_Division: "Test", Client_Survey: "Test 01", Client_Survey_Name: "Test 01", Old_Production_Client_Name: "test", Old_Production_Division_Name: "test", Dialing_Form: "Not tested in new system.", Alert_Brand: "test", Alert_Org_Name: "test", Alert_Logically: 0, Alert_Subject: "There shouldn't be alerts for this account!", Alert_To: "test", Alert_CC: "test", Alert_Instructions: "No alerts.", SQL_Alert_Criteria: "0=1", Mailmerge_Template: nil, SQL_Mailmerge_Criteria: nil, Rep_Survey_Note: nil, Alert_Contact_Name: nil, Alert_Contact_Phone: nil, Alert_Contact_EMail: nil, Sunday: 0, Monday: -1, Tuesday: -1, Wednesday: -1, Thursday: -1, Friday: -1, Saturday: 0, Added_At: "2006-03-28 14:56:42", Added_By: "test", Last_Modified_At: "2009-07-03 22:21:40", Last_Modified_By: "test", Caller_Id: "test", Record_Calls: 1>
s.Record_Calls = 0
=> 0
s.save(:keywords => 'LOW_PRIORITY')
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'Client,Client_Division,Client_Survey' in 'where clause': UPDATE LOW_PRIORITYClient_Survey_Information
SETAlert_Contact_Phone
= NULL,Last_Modified_At
= '2009-07-03 22:21:40',Rep_Survey_Note
= NULL,Alert_Subject
= 'There shouldn't be alerts for this account!',Alert_Contact_Name
= NULL,Wednesday
= -1,Client_Survey_Information_ID
= 148,Alert_Org_Name
= 'test',Added_At
= '2006-03-28 14:56:42',Client_Survey_Name
= 'EAP Bench Test 01',Alert_To
= 'test',Old_Production_Division_Name
= 'test',SQL_Alert_Criteria
= '0=1',Alert_Instructions
= 'No alerts.',Record_Calls
= 0,Friday
= -1,Alert_Logically
= 0,Dialing_Form
= 'Not tested in new system.',Old_Production_Client_Name
= 'test',Last_Modified_By
= 'test',Monday
= -1,Sunday
= 0,Thursday
= -1,Caller_Id
= 'test',Alert_Brand
= 'test',Tuesday
= -1,Mailmerge_Template
= NULL,SQL_Mailmerge_Criteria
= NULL,Saturday
= 0,Alert_CC
= 'test',Alert_Contact_EMail
= NULL,Added_By
= 'test' WHEREClient,Client_Division,Client_Survey
= '--- !seq:CompositePrimaryKeys::CompositeIds \n- Test Client\n- Test\n- Test 01\n'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:inlog' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:323:in
execute'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:265:inupdate_sql' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:338:in
update_sql'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:49:inupdate_without_query_dirty' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:18:in
update'
from /usr/local/lib/ruby/gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/create_and_update.rb:268:inupdate' from /usr/local/lib/ruby/gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/create_and_update.rb:229:in
create_or_update'
from /usr/local/lib/ruby/gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/create_and_update.rb:206:in `save'
Hi
I have imported data using ar_extensions 0.9.3 into sqlite 1.3.2 with impressive results. Now I want to process that data updating some fields in same table. The table has :id as primary key
options = {:validate => false, :on_duplicate_key_update => [:x]}
columns = [ :id,:x]
igcfs = Igcfile.find(:all) # get files
igcfs.each do |igcf| # for each file
ps=[]
igcps = igcf.igcpoint(:all, :order => 'seq_secs') # get points
igcps.each do |igcp| # for each point
ps<<[igcp.id,igcp.x] # push data to array
end
Igcpoint.import columns, ps, options # update DB
end
development.log sais - WARNING: Can't mass-assign these protected attributes: id
I see that this issue turned up a year ago. Not fixed yet?
http://zdennis.lighthouseapp.com/projects/14379/tickets/26-cant-import-protected-attributes
If there is no fix then it looks like a workaroundmight be to create a 2nd unique key and use that instead of :id
Peter
This page http://continuousthinking.com/tags/arext says ar-extensions in in 0.8.2, but this github repo and this page http://rubyforge.org/projects/arext/ say 0.9.2
Can the continuousthinking.com page link to one of these, or be kept up to date?
Not Found
The requested URL /tags/arext was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The list of dependencies for ar-extensions doesn't appear to be absolutely correct. I have a Ruby (non-rails) project that uses ar-extensions for bulk insertion of data into the mysql db, and requires activerecord and activesupport from the 2.3.8 rails branch. On a fresh machine, in order to install ar-extensions with these versions in place I have to do a
gem install --ignore-dependencies ar-extensions
to prevent it from updating these (and adding in a number of other gems as a consequence).
Have I missed something, since I'm sure that I had ar-extensions working with 2.3.8 originally?
Paul
Without ar-extensions:
>> User.scoped(:conditions => {"users.name" => "bob"})
User Load (1.0ms) SELECT * FROM `users` WHERE (`users`.`name` = 'bob')
With ar-extensions:
>> User.scoped(:conditions => {"users.name" => "bob"})
User Load (0.0ms) Mysql::Error: Unknown column 'users.users.login' in 'where clause': SELECT * FROM `users` WHERE (`users`.`users.login` = 'bob')
ar_extensions is great. But does it bog down with large imports. Look at this data for various file sizes
file.................................num_recs........recs/sec
public/data/095LCQJ1.igc 3117 164
public/data/656C3X61.IGC 1224 348
public/data/657C3X61.IGC 809 420
public/data/65EC3X62.IGC 2150 234
public/data/65RC3X62.IGC 4140 117
I suspect there is a sweet spot for import size probably order 100 recs
Peter
PS does activerecord_import work on rails 2.3.9 ruby 1.8.7. I couldnt get it to work so used ar_extensions instead
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.