Check out https://rubygems.org/gems/dm-ar-finders there's a find_by_sql
method in there: http://rubydoc.info/gems/dm-ar-finders/1.2.0/frames
Beyond that you can also fire off queries directly at a repository's
adapter as well:
1.9.3p194 :004 > DataMapper.repository.adapter.select('select * from
candidates limit 1')
=> [#<struct id=1, name="Peter Kinder", slug="peter-kinder",
incumbent=true, url=nil>]
But as you can see, that doesn't give you wrapped models and a collection
back. (the find_by_sql method above does)
On Wed, Jul 25, 2012 at 12:22 PM, Mario Camou <[email protected]> wrote:
> I also need to do this, I want to issue a command to MySQL to set the
> Transaction Isolation level but haven't found out how to send raw SQL
> statements through DataMapper. Any takers?
>
>
> On Thursday, May 3, 2012 8:19:43 AM UTC+2, Johannes Held wrote:
>>
>> Hello list,
>>
>> I’m wondering what's the proper way to execute a SQL statement via
>> DataMapper.
>>
>> Assume I these models are created at runtime:
>>
>> class Bar
>> include DataMapper::Resource
>> property :id, :Serial
>> end
>>
>> class Foo
>> include DataMapper::Resource
>> property :a, :Serial
>> property :b, :Serial
>> belongs_to Bar, :key => true
>> end
>>
>> Now I want to create a view (and a model to mirror that view):
>> create view foo_count as
>> select a, b, count(bar) as count
>> from foo
>> group by a, b
>>
>> How can I use DataMapper to execute this statement?
>> Is there a way to use the name system of DataMapper?
>>
>> --
>> Cheers, Johannes
>>
> --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/datamapper/-/BBN4m098lKsJ.
>
> 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/datamapper?hl=en.
>
--
Ted Han
@knowtheory <http://twitter.com/knowtheory>
DocumentCloud
Investigative Reporters & Editors
--
You received this message because you are subscribed to the Google Groups
"DataMapper" 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/datamapper?hl=en.