8000 problem when FK is not an integer id · Issue #28 · flyerhzm/eager_group · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

problem when FK is not an integer id #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dfl opened this issue Nov 15, 2023 · 0 comments
Open

problem when FK is not an integer id #28

dfl opened this issue Nov 15, 2023 · 0 comments

Comments

@dfl
Copy link
dfl commented Nov 15, 2023

I have an association where I use a text string for my primary key.

      has_many :children, class_name: "ActsAsTaggableOn::Tag", foreign_key: :parent_name, primary_key: :name, dependent: :nullify
      define_eager_group :children_count, :children, :count, :*

when I do eager_group count, it is associating with the object's id instead of the association's PK (:name)

irb(main):016:0> tag = ActsAsTaggableOn::Tag.find_by(name: "Africa")                    
irb(main):017:0> tag.children.count
  ActsAsTaggableOn::Tag Count (0.5ms)  SELECT COUNT(*) FROM "aat_tags" WHERE "aat_tags"."parent_name" = $1  [["parent_name", "Africa"]]
=> 60                                                                                     
irb(main):018:0> tag.children_count
  ActsAsTaggableOn::Tag Count (1.2ms)  SELECT COUNT(*) AS "count_all", "aat_tags"."parent_name" AS "aat_tags_parent_name" FROM "aat_tags" WHERE "aat_tags"."parent_name" = $1 GROUP BY "aat_tags"."parent_name"  [["parent_name", "3018"]]
=> 0                                                                                      
irb(main):019:0> tag.id
=> 3018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0