@dbussink in theory the Oracle adapter could also generate the
accessors on the fly too, couldn't it?
However, the Structs approach is pretty interesting and sounds cleaner
indeed.

- Matt


On Aug 3, 10:31 am, Dirkjan Bussink <[email protected]> wrote:
> On 31 Jul 2009, at 20:24, Nate Wiger wrote:
>
>
>
> > I've tried to dig thru the docs for delegated properties/etc, but
> > can't seem to find the magic incantation in DM.  How would I achieve
> > this in DM?
>
> Well, what you see here is the result of a major difference in how DM  
> is architected compared to AR. ActiveRecord creates object by mapping  
> the result sets directly, but DataMapper is explicit about this in  
> it's model definitions. This means that you never magically get  
> a .rank method on a model, even if it's returned by find_by_sql.
>
> find_by_sql is also considered a kind of bastard child in DM and  
> really isn't compatible with DM's goal of being storage engine agnostic.
>
> If you want to run raw queries with DM, I always use the following  
> approach:
>
> data = DataMapper.repository.query("select high_score, rank(over  
> (order by avg_score desc)) as rank from scores")
>
> This will return an array of Struct's which can be iterated over like  
> the following:
>
> data.each do |line|
>    line.high_score => 1000
>    line.rank       => 100
> end
>
> Imho this also better fits the use case, since cramming non model  
> properties into an ActiveRecord object has always felt strange to me.
>
> --
> Regards,
>
> Dirkjan Bussink
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to