Forum: Ferret how to select only some fields?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E5a578d46a1ea27124cf40b6f783be51?d=identicon&s=25 david (Guest)
on 2007-03-23 23:35
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?
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-03-26 14:04
(Received via mailing list)
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
kraemer@webit.de | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
E5a578d46a1ea27124cf40b6f783be51?d=identicon&s=25 david (Guest)
on 2007-03-26 18:09
Jens Kraemer 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..
:(
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-03-27 10:30
(Received via mailing list)
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
kraemer@webit.de | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
E5a578d46a1ea27124cf40b6f783be51?d=identicon&s=25 david (Guest)
on 2007-03-27 14:39
Jens Kraemer 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 :)
This topic is locked and can not be replied to.