On Mar 4, 2:58 am, pachl <[email protected]> wrote:
> I figured there would be class method called `virtual_accessor' or
> something. Well I didn't use `def_column_accessor'. Instead, I defined
> an instance method that simply returns the proper object from the
> values hash because it is readonly:
>
>     def body_preview
>       self[:body_preview]
>     end

That should work fine.  def_column_accessor would define exactly the
same getter.

> Once you helped me fix my virtual column issue, I uncovered another
> problem, as you might have guessed. My select in the code snippet was
> a mess:
>
>     .select(:headline, 'substring(body from "^.*?</
> p>")'.as(:body_preview))
>
> After looking at the Sequel docs, it looks like I need Virtual Row
> Blocks. I just could not get this thing to work properly, so I
> defaulted literal SQL:
>
>     .select(:headline, "substring(body from '^.*?</p>') AS
> body_snippet".lit)
>
> The ORM version was getting very cumbersome and confusing compared to
> the raw SQL. Thank god for #lit in my case.

The virtual row way would be:

  .select{[headline, substring("body from '^.*?</
p>'".lit).as(body_snippet)]}

There's not a clean way to do it without lit because the SQL substring
function doesn't use the normal comma-separated-arguments calling
connection.

Thanks,
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