Created
June 11, 2018 19:52
-
-
Save CodePint/dd39072d9859a26d18f18e7dbb7526f3 to your computer and use it in GitHub Desktop.
search climbs by gym
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Climb < ApplicationRecord | |
include PgSearch | |
belongs_to :user | |
belongs_to :route | |
has_many :comments | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Gym < ApplicationRecord | |
include PgSearch | |
has_many :routes | |
has_many :memberships | |
has_many :users, :through => :memberships | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Route < ApplicationRecord | |
include PgSearch | |
belongs_to :gym | |
belongs_to :user | |
has_many :climbs | |
has_many :comments | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task: find which climbs are set at a particular gym | |
example: | |
@gym = gym.find(name: "stronghold") | |
@routes = Climb.where(gym_id: @gym.id) | |
^ STILL doesnt do quite what i want. allows me to do @gym.climbs but not Climb.where(gym_id: @gym.id)
@climbs.joins(:route).where(gym_id: @gym.id)
I know something like this ^ should maybe work as well.
What's wrong with @gym.climbs ?
absolutely nothing....ive got to stop doing 10 hours in front of a screen. (just picked this back up after yesterday)
I think it felt alien to be doing the lookup on gyms instead of climbs, this was part of a search function im finishing.
sorry for wasting your time.
side note, im really enjoying postgres. got this up n running:
#pg search scope for route identifier
pg_search_scope(
:search_identifier,
:against => %i(identifier),
:using => {
:tsearch => {:prefix => true},
:trigram => {:threshold => 0.1}
}
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
has_many :climbs, :through => :routes
has_one :gym, :through => :routes