On Nov 13, 4:47 pm, Wardrop <[email protected]> wrote:
> Thanks for the reply. A different but related question. If I wanted to
> do this without using Sequel's DSL, but instead raw SQL, what's the
> best way to integrate this into the existing model.
>
> To give an example, let's say my Post model looked like this...
>
> class Post < Sequel::Model
>   one_to_many :comment
>   one_to_many :postmeta
>
>   def self.blogs
      with_sql('SQL')
>   end
> end
>
> Where inside self.blogs, is a raw SQL query. What's generally the best
> way to run and return that raw sequel query from within the context of
> the model. Is a DB.run("SELECT * FROM post ...") the only real option,
> or is there something else I can do? I guess ideally, it would be good
> to get the database object not from the constant 'DB', but from the
> model itself. Is that possible?
>
> I've decided that I want to use raw SQL for any tricky SQL statements
> (those involving multiple joins, sub-queries, etc), so I'm just trying
> to find the best way to do put raw SQL into an existing model.

In this case, I assume you want to return the results as Post
instances, so you just want to call the with_sql method on the model,
which returns a copy of the dataset that uses the specific SQL you
give it.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to