#2 ✓resolved
cesidio

Add joins to conditions

Reported by cesidio | September 22nd, 2008 @ 01:29 PM

If we need to add joins tables to our search query, it would be nice to benefit of Searchgasm cleaner way of specifing conditions. like in the following:

@posts = Post.all(:joins => :blog, :conditions => ['blog.url = ?', "http://.."])

it would became:

@posts = Post.all(:joins => :blog, :conditions => {:blog => {:url_contains => "url"}})

this is not a good example because it is evident that there would be a belongs_to relationship between Post and Blog, but let's just put the case there isn't

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson September 22nd, 2008 @ 01:39 PM

    • State changed from “new” to “open”

    I'm a little confused, do you mind clarifying a little bit more? Searchgasm automatically includes based on what it knows. So if you order or set conditions on associations it will automatically include them.

  • cesidio

    cesidio September 22nd, 2008 @ 02:28 PM

    ok you said:

    So if you order or set conditions on associations it will automatically include them.

    You are talking about associations, I am talking about joins

  • Ben Johnson

    Ben Johnson September 22nd, 2008 @ 02:38 PM

    Ok, do you mind clarifying a little bit more so I can understand exactly what you are trying to do. Thanks!

  • cesidio

    cesidio September 22nd, 2008 @ 02:50 PM

    sorry about it, i didn't expain it properly, I will use the full domain i am working on at the moment

    Post has_many :linked_posts has_many :links, :through => :linked_posts

    Link has_many :linked_posts has_many :posts, :through => :linked_posts

    belongs_to :target_paper, :class_name => 'Paper', :foreign_key => 'target_paper_id'

    LinkedPost belongs_to :post belongs_to :link

    Paper

    At the moment I have do the following:

    @posts = Post.all(:joins => {:linked_posts => {:link => :target_paper}}, :conditions => ['papers.url = ?', params[:url]] if params[:url])

    it would be nice if I could specify conditions in a more searchgasm way

  • Ben Johnson

    Ben Johnson September 22nd, 2008 @ 08:54 PM

    • State changed from “open” to “resolved”

    Hi, I released a new version that uses joins instead of include. Update and you should see it take effect. Joins are much faster. Let me know if this fixes your problem. Thanks.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Pages