Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to ::Sequel::Dataset.class_eval when doing raw query #1

Closed
wants to merge 1 commit into from
Closed

Fix to ::Sequel::Dataset.class_eval when doing raw query #1

wants to merge 1 commit into from

Conversation

jmthomas
Copy link

I'm using Sequel in my rails project indirectly and not inheriting from Sequel::Model. Thus I was crashing since I didn't have model defined. I changed the code to add defined?(model) but then I didn't have first_source defined (because again I'm doing raw queries). So I changed it to return the raw SQL query by calling the sql method. This might not be desirable in the default case but since my SQL queries weren't getting connected to the results page, it was the only way to know what was going on.

If you want to test my use case simply define a model like this:

require 'sequel'
class Packet
  @@db = Sequel.oracle(<connection params>)
  def self.all(table)
    @@db["select * from #{table}"]
  end
end

…odel. If model is not found output the SQL directly.
@tmm1
Copy link
Owner

tmm1 commented Dec 14, 2010

Thanks. Perhaps we should also check if first_source is defined, and use that instead. Otherwise fallback to "raw" instead of including the sql string itself.

@jmthomas
Copy link
Author

I think if first_source is defined it also means that model is defined. Justin George from NewRelic told me to try to the following in my model to avoid the model problem:

def self.model; "MyModelName"; end

However, this did not help and I haven't looked into why. I also don't know why I wasn't getting my SQL queries linked to the output which is why I put in the sql string itself.

@jmthomas jmthomas closed this Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants