You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Project class that has multiple Topics. Topic slugs need to be unique across all topics within the same project.
My routes are like localhost/:project/sub-topic-slug
Topics class uses friendlyId and an STI table table has SubTopics
class Topic
extend FriendlyId
friendlyId :slug_candidates, use: :scoped, scope: :project
SubTopic1 < Topic
FriendlyId is allowing slugs to be same for the SubTopic1 and SubTopic2. When I look at the SQL generated for scope it is automatically adding type column from the STI. But the documentation says that slugs will not be unique per subclass by default. How can I change this behavior?
Looking at the source code the method "scope_for_slug_generator":
in slugged.rb uses: scope = self.class.base_class.unscoped
but in scoped.rb uses: relation = self.class.unscoped.friendly
Changing this line to self.class.base_class.unscoped.friendly fixes the problem.
Thanks.
The text was updated successfully, but these errors were encountered:
mpasad
changed the title
Use of STI can cause "duplicate entry" errors
Use of STI with scoped can cause "duplicate entry" errors
Apr 27, 2016
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am using Rails 4.1.14.2 and FriendlyId 5.0.3
I have a Project class that has multiple Topics. Topic slugs need to be unique across all topics within the same project.
My routes are like localhost/:project/sub-topic-slug
Topics class uses friendlyId and an STI table table has SubTopics
class Topic
extend FriendlyId
friendlyId :slug_candidates, use: :scoped, scope: :project
SubTopic1 < Topic
FriendlyId is allowing slugs to be same for the SubTopic1 and SubTopic2. When I look at the SQL generated for scope it is automatically adding type column from the STI. But the documentation says that slugs will not be unique per subclass by default. How can I change this behavior?
Looking at the source code the method "scope_for_slug_generator":
in slugged.rb uses: scope = self.class.base_class.unscoped
but in scoped.rb uses: relation = self.class.unscoped.friendly
Changing this line to self.class.base_class.unscoped.friendly fixes the problem.
Thanks.
The text was updated successfully, but these errors were encountered: