Use "local_area.name" or :"local_area.name"

Bryan


On Wed, Nov 28, 2012 at 6:01 PM, tonym <[email protected]> wrote:
> Hi Bryan,
> thanks.  I can't get this to work though...
> How do I reference 'local_area.name' in the controller, to get a sort on
> that column?
> I've tried fields='local_area.name...etc  and then my controller is...
>
>   def index
>     hobo_index do
>       self.this = self.this.include(:local_area)
>       self.this = self.this.search(params[:search], :user_id, :name) if
> params[:search]
>       self.this = self.this.order_by(parse_sort_param(:local_area.name)) if
> params[:sort]
>     end
>   end
>
>
> I'm assuming this needs a SQL join, to be able to order by the name rather
> than the id.  Tried with and without an 'include', couldn't get a 'join' to
> work.
> The include creates an outer join, not sure it's a good idea though.
> With or without an include, this fails on the sort param :local_area.name
> which I must be referencing incorrectly?
>
> Thanks, Anthony.
>
>
> On Wednesday, November 28, 2012 6:02:06 PM UTC, Bryan Larsen wrote:
>>
>> It should work if you use fields="local_area.name" rather than
>> fields="local_area".   If you need access to local_area in your view,
>> you should be able to use this_parent rather than this.
>>
>> Bryan
>>
>>
>> On Wed, Nov 28, 2012 at 10:46 AM, tonym <[email protected]> wrote:
>> > Thanks Bryan,
>> >
>> > that works, and neat too :)
>> >
>> > Just one 'gotcha' is that all the columns that are belongs_to
>> > relationships
>> > try to sort without referencing the id.
>> > e.g. http://localhost:3000/my_venues?sort=local_area is in the 'local
>> > area'
>> > column link,  but I can only get the sort with 'local_area_id'.
>> > I can work around this, but is this a fault or is there a way to sort by
>> > 'local area' without the id - i.e. can we sort alphabetically on the
>> > parent
>> > name?
>> >
>> > Thanks, Anthony
>> >
>> >
>> >
>> > On Wednesday, November 28, 2012 2:20:58 PM UTC, Bryan Larsen wrote:
>> >>
>> >> Actually, the call to index_response is not necessary.   Old
>> >> documentation was less misleading than I thought.
>> >>
>> >>   def index
>> >>     hobo_index do
>> >>       self.this = self.this.search(params[:search], :name) if
>> >> params[:search]
>> >>       self.this = self.this.order_by(parse_sort_param(:name,
>> >> :quantity)) if params[:sort]
>> >>     end
>> >>   end
>> >>
>> >> Bryan
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Hobo Users" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/hobousers/-/t6yw5VLjnJ4J.
>> >
>> > 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/hobousers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/LxcuxPHW1RwJ.
>
> 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/hobousers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en.

Reply via email to