Skip to content

undefined method [] and Object doesn't support #inspect #194

@ringe

Description

@ringe

I have a TimeCard model with the following method

1.9.2p290 :002 > TimeCard.import_heavy_job_time_cards 200
  SQL (0.5ms)  USE [HeavyJob]
  Timedetl Load (36033.3ms)  EXEC sp_executesql N'SELECT TOP (200) timedetl.total_reg, timedetl.total_ot, timedetl.total_oth, timedetl.foreman, timedetl.card_num, timedetl.date, timedetl.empeqp_code, timedetl.jobcode FROM [TIMEDETL] INNER JOIN ( SELECT MAX(card_num) as max_num, foreman, date, jobcode FROM timedetl GROUP BY foreman, date, jobcode ) mxCards
 ON timedetl.card_num = mxCards.max_num AND timedetl.foreman = mxCards.foreman AND timedetl.date = mxCards.date AND timedetl.jobcode = mxCards.jobcode WHERE (timedetl.empeqp_code BETWEEN ''110128'' AND ''993017'') AND (timedetl.jobcode NOT IN (N''TRAINING'',N''JOBMAST'',N''TRAFFIC'',N''HRSAFETY'',N''ESTIMATING''))'
NoMethodError: undefined method `[]' for nil:NilClass

The import_heavy_job_time_cards method uses my Timedetl model's get_cards method and tries to do an .each on it.

1.9.2p290 :004 > s = Timedetl.get_cards 2
  Timedetl Load (1766.2ms)  EXEC sp_executesql N'SELECT TOP (2) timedetl.total_reg, timedetl.total_ot, timedetl.total_oth, timedetl.foreman, timedetl.card_num, timedetl.date, timedetl.empeqp_code, timedetl.jobcode FROM [TIMEDETL] INNER JOIN ( SELECT MAX(card_num) as max_num, foreman, date, jobcode FROM timedetl GROUP BY foreman, date, jobcode ) mxCards
 ON timedetl.card_num = mxCards.max_num AND timedetl.foreman = mxCards.foreman AND timedetl.date = mxCards.date AND timedetl.jobcode = mxCards.jobcode WHERE (timedetl.empeqp_code BETWEEN ''110128'' AND ''993017'') AND (timedetl.jobcode NOT IN (N''TRAINING'',N''JOBMAST'',N''TRAFFIC'',N''HRSAFETY'',N''ESTIMATING''))'
(Object doesn't support #inspect)
 =>  
1.9.2p290 :005 > s
 => [#<Timedetl >, #<Timedetl >]

The latter model looks like this:

# Time cards from HeavyJob queries
class Timedetl < ActiveRecord::Base
  self.table_name = 'TIMEDETL'

  # Get TimeCards from the TIMEDETL table
  def self.get_cards(limit)
    return nil unless TulanCheck.do

    jobs = ["TRAINING"] # Excluded job codes

    s = Timedetl.select("timedetl.total_reg, timedetl.total_ot, timedetl.total_oth, timedetl.foreman, timedetl.card_num, timedetl.date, timedetl.empeqp_code, timedetl.jobcode"
      ).joins("INNER JOIN ( SELECT MAX(card_num) as max_num, foreman, date, jobcode FROM timedetl GROUP BY foreman, date, jobcode ) mxCards
      ON timedetl.card_num = mxCards.max_num AND timedetl.foreman = mxCards.foreman AND timedetl.date = mxCards.date AND timedetl.jobcode = mxCards.jobcode"
      ).where("timedetl.empeqp_code BETWEEN '32238' AND '234017'"
      ).where("timedetl.jobcode NOT IN (?)", jobs
             ).limit(limit)
    s
  end
end
Timedetl.establish_connection(
  adapter: "sqlserver",
  mode: "dblib",
  host: "server05",
  database: "HeavyJob"
  timeout: 0)

Why would Timedetl.get_cards return an empty response but still set the s parameter?

Could this be related to http://stackoverflow.com/questions/7690697/object-doesnt-support-inspect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions