How to select only some fields?

hi, how can i select only some fields when ferret do the query? like a
:select => ‘id’, for the find…i’ve tried to do it where i do the
:include => [:something], but it doesn’t work…is it right or i’ve to
put it in another place?

On Fri, Mar 23, 2007 at 11:35:20PM +0100, david wrote:

hi, how can i select only some fields when ferret do the query? like a
:select => ‘id’, for the find…i’ve tried to do it where i do the
:include => [:something], but it doesn’t work…is it right or i’ve to
put it in another place?

the right place is the second argument hash of find_by_contents:

Model.find_by_contents(query, {}, { :select => ‘id’ })
I didn’t ever try with select but if it’s a valid option to find :all,
it should work.

Jens


Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa

Jens K. wrote:

the right place is the second argument hash of find_by_contents:

Model.find_by_contents(query, {}, { :select => ‘id’ })
I didn’t ever try with select but if it’s a valid option to find :all,
it should work.

Jens

i tried with this: self.find_by_contents(query, options, {:select =>
‘users.nick’, :include => [:user, :categories]}) and it doesn’t work…
:frowning:

Jens K. wrote:

I just tried this myself and you’re right, it doesn’t work - that is,
all fields get selected.

If you try this with plain active record’s find method, you’ll see that
even then your :select option will be ignored when an :include option is
given. So unfortunately there’s nothing acts_as_ferret can do about
this.

so i should use :join instead of :include?
:joins: An SQL fragment for additional joins like “LEFT JOIN comments ON
comments.post_id = id”. (Rarely needed). The records will be returned
read-only since they will have attributes that do not correspond to the
table‘s columns. Pass :readonly => false to override.

i don’t need to edit them, just to show them, so a simple :joins it can
be ok, without :readonly => false…
i’ll try :slight_smile:

On Mon, Mar 26, 2007 at 06:09:41PM +0200, david wrote:

i tried with this: self.find_by_contents(query, options, {:select =>
‘users.nick’, :include => [:user, :categories]}) and it doesn’t work…

I just tried this myself and you’re right, it doesn’t work - that is,
all fields get selected.

If you try this with plain active record’s find method, you’ll see that
even then your :select option will be ignored when an :include option is
given. So unfortunately there’s nothing acts_as_ferret can do about
this.

Jens


Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa