If you want a class method that doesn't return an instance of your
model, I think you'll have to stick with my suggestion from another
thread:

def my_instance_method
  rows = repository.adapter.select <<-SQL
    select
      blah blah blah from my_model inner join blah blah blah
    SQL

  # rows is an array of structs; to return an array of hashes do the
following:
  new_rows = rows.map { |row| Hash[row.members.zip(row.values)] }
end

Here, new_rows won't be an array of a specific model type, but you can
likely construct one from the hash array.

On Dec 6, 8:39 am, Ted Han <[email protected]> wrote:
> .find_by_sql is a class method which does not allow for chaining.
>
> Chaining functions by taking the query object that's stored on a collection,
> and modifying/updating it with a new query.
>
> The only problem is when you call Model.find_by_sql, there *is* no query
> object, because you're specifying a data set by directly invoking SQL.
>
> -T
>
> On Mon, Dec 6, 2010 at 12:34 AM, dev2 <[email protected]> wrote:
> > Hi,
> > This is a really cool function of datamapper. Kudos to snusnu and
> > thanks.
>
> > I have some questions about it
>
> > Is it possible to use find_by_sql in an instance, or can it only be
> > used as a class method?
>
> > Is it possible to have it returns a collection of a type other than
> > the class its called from? (for example ( Person, Place, PersonPlace -
> > lets say I want to do some complex querying to find places that have
> > people that meet certain criteria.  I could do this in the Person
> > model, but it seems to feel better having the Place model do it (with
> > a function called specific_people).  place = Place.first;
> > place.specific_people)
>
> > I'm sure more questions will trickle from this.
>
> > I really appreciate any help you can offer.  Also, there doesn't seem
> > to be much in the way of docs for this feature, so if I missed them
> > please let me know where they are :)
>
> > Thanks
>
> > --
> > 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]<datamapper%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/datamapper?hl=en.

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