Skip to content

Loading…

The metafied check fails with rails 3 or 3.1 #2

Merged
merged 5 commits into from

7 participants

@cajun-code

NoMethodError (undefined method `metafied?' for #Class:0x00000103436be8):

I changed this to run in a try method. This has been tried with both rails 3 and 3.1.

@dglancy

Thanks for the fix, I got the same issue.

@h8h
h8h commented

Yeah! Thanks for the fix.

But fix 071b2a9 made problems with the mysql Database.

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0'' at line 1: SELECT categories.name as name FROM categories ORDER BY categories.name asc LIMIT 10 OFFSET '0'

@edit:
I undo the fix 071b2a9 and it works fine.

@cajun-code

when I ran it against mysql it works fine. I can go in and add a forced to_i on the string but the offset is working.

Ticket Load (46.8ms) SELECT swtickets.ticketid as ticketid, swdepartments.title as queue, swdepartments.title as department, swtickets.subject as subject, swticketstatus.title as status, swticketpriorities.title as priority, swtickets.dateline as dateline FROM swtickets INNER JOIN swdepartments ON swdepartments.departmentid = swtickets.departmentid INNER JOIN swticketpriorities ON swticketpriorities.priorityid = swtickets.priorityid INNER JOIN swticketstatus ON swticketstatus.ticketstatusid = swtickets.ticketstatusid INNER JOIN swusers ON swusers.userid = swtickets.userid ORDER BY swtickets.ticketid asc LIMIT 10 OFFSET 0

@cajun-code

@h8h I updated it to force the offset and limit to integers. update it and try and see if it works for you.

@h8h
h8h commented

@cajun-code yes this work fine. Thanks!

@TravisBenning

@cajun-code thanks for this fix!

@tzoro

How to pull data like @company.invoices. @company is current company that i want to show invoices.

@rbetancor

I'm getting problems with ssociation columns, on a very simple example with to models users and bears with a one to many relation beetween them, one User may have many Bears, on the bear.index view I have this:

<%= datatable('bear', { :origin => { :type => 'string',
:label => 'Origin',
:width => '20%' },
:user_name => { :type => 'string',
:label => 'Name',
:column => 'users.name',
:width => '15%' }
}) %>

I got this error:

Started GET "/rdtable/bear/origin,user_name:users:name?sEcho=1&iColumns=2&sColumns=&iDisplayStart=0&iDisplayLength=10&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&iSortingCols=1&iSortCol_0=0&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&=1325673629914" for 127.0.0.1 at 2012-01-04 10:33:26 +0000
Processing by DatatablesController#dataset as JSON
Parameters: {"sEcho"=>"1", "iColumns"=>"2", "sColumns"=>"", "iDisplayStart"=>"0", "iDisplayLength"=>"10", "sSearch"=>"", "bRegex"=>"false", "sSearch_0"=>"", "bRegex_0"=>"false", "bSearchable_0"=>"true", "sSearch_1"=>"", "bRegex_1"=>"false", "bSearchable_1"=>"true", "iSortingCols"=>"1", "iSortCol_0"=>"0", "sSortDir_0"=>"asc", "bSortable_0"=>"true", "bSortable_1"=>"true", "
"=>"1325673629914", "model"=>"bear", "columns"=>"origin,user_name:users:name"}
(0.4ms) SELECT COUNT() FROM "bears"
CACHE (0.0ms) SELECT COUNT(
) FROM "bears"
Bear Load (0.8ms) SELECT bears.origin as origin, users.name as user_name FROM "bears" ORDER BY bears.origin asc LIMIT 10 OFFSET 0
SQLite3::SQLException: no such column: users.name: SELECT bears.origin as origin, users.name as user_name FROM "bears" ORDER BY bears.origin asc LIMIT 10 OFFSET 0
Completed 500 Internal Server Error in 39ms

Could someone give me a clue about what I'm doing wrong ?

@supercleanse supercleanse merged commit e94a116 into caseproof:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
29 lib/datatables/activerecord_methods.rb
@@ -5,13 +5,16 @@ def datatable( params )
curr_model = self
table_name = curr_model.table_name
- if curr_model.metafied?
- metas = curr_model.metafied_attrs || []
- else
+ begin
+ if curr_model.try :metafied?
+ metas = curr_model.metafied_attrs || []
+ else
+ metas = []
+ end
+ rescue NoMethodError
metas = []
end
-
- sql_opts = { :select => [], :limit => "", :order => "", :joins => [], :conditions => "" }
+ sql_opts = { :select => [], :offset=>"", :limit => "", :order => "", :joins => [], :conditions => "" }
columns = []
full_columns = []
@@ -22,11 +25,11 @@ def datatable( params )
dcols.each do |col|
col = col.split(':')
if col.length > 1 # association (already assumed we're joined within a scope)
- col_fmt = "`#{col[1].to_s}`.`#{col[2].to_s}`"
+ col_fmt = "#{col[1].to_s}.#{col[2].to_s}"
elsif metas.include? col.first.to_sym
- col_fmt = "`m_#{col.first.to_s}`.`meta_value`"
+ col_fmt = "m_#{col.first.to_s}.meta_value"
else
- col_fmt = "`#{table_name.to_s}`.`#{col.first.to_s}`"
+ col_fmt = "#{table_name.to_s}.#{col.first.to_s}"
end
columns.push col.first.to_s
@@ -36,7 +39,9 @@ def datatable( params )
# Paging
if params['iDisplayStart'] and params['iDisplayLength'] != '-1'
- sql_opts[:limit] = "#{params['iDisplayStart']},#{params['iDisplayLength']}"
+ # sql_opts[:limit] = "#{params['iDisplayStart']},#{params['iDisplayLength']}"
+ sql_opts[:limit] = "#{params['iDisplayLength']}".to_i
+ sql_opts[:offset] = "#{params['iDisplayStart']}".to_i
end
# Ordering
@@ -86,21 +91,21 @@ def datatable( params )
# Query
if dscope.nil?
# Scope model
- records = curr_model.select( sql_opts[:select] ).limit( sql_opts[:limit] ).order( sql_opts[:order] ).where( sql_opts[:conditions] ).joins(sql_opts[:joins])
+ records = curr_model.select( sql_opts[:select] ).limit( sql_opts[:limit] ).offset(sql_opts[:offset]).order( sql_opts[:order] ).where( sql_opts[:conditions] ).joins(sql_opts[:joins])
# Records Found
filtered_total = curr_model.count( :select => "*", :conditions => sql_opts[:conditions], :joins => sql_opts[:joins] )
# Total Found
total = curr_model.count( :select => "*" )
elsif params[:id].nil?
# Scope model
- records = curr_model.send( dscope.to_s ).select( sql_opts[:select] ).limit( sql_opts[:limit] ).order( sql_opts[:order] ).where( sql_opts[:conditions] ).joins(sql_opts[:joins])
+ records = curr_model.send( dscope.to_s ).select( sql_opts[:select] ).limit( sql_opts[:limit] ).offset(sql_opts[:offset]).order( sql_opts[:order] ).where( sql_opts[:conditions] ).joins(sql_opts[:joins])
# Records Found
filtered_total = curr_model.send( dscope.to_s ).count( :select => "*", :conditions => sql_opts[:conditions], :joins => sql_opts[:joins] )
# Total Found
total = curr_model.send( dscope.to_s ).count( :select => "*" )
else
# Scope model
- records = curr_model.send( dscope.to_s, params[:id] ).select( sql_opts[:select] ).limit( sql_opts[:limit] ).order( sql_opts[:order] ).where( sql_opts[:conditions] ).joins(sql_opts[:joins])
+ records = curr_model.send( dscope.to_s, params[:id] ).select( sql_opts[:select] ).limit( sql_opts[:limit] ).offset(sql_opts[:offset]).order( sql_opts[:order] ).where( sql_opts[:conditions] ).joins(sql_opts[:joins])
# Records Found
filtered_total = curr_model.send( dscope.to_s, params[:id] ).count( :select => "*", :conditions => sql_opts[:conditions], :joins => sql_opts[:joins] )
# Total Found
View
BIN vendor/assets/images/.DS_Store
Binary file not shown.
View
BIN vendor/assets/images/Sorting icons.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/back_disabled.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/back_enabled.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/favicon.ico
Binary file not shown.
View
BIN vendor/assets/images/forward_disabled.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/forward_enabled.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/sort_asc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/sort_asc_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/sort_both.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/sort_desc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN vendor/assets/images/sort_desc_disabled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Something went wrong with that request. Please try again.