Skip to content
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

References with array keys #52

Closed
vladfaust opened this Issue May 30, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@vladfaust
Copy link
Member

vladfaust commented May 30, 2018

E.g.

CREATE TABLE tags(
  id SERIAL PRIMARY KEY,
  content VARCHAR(64) NOT NULL,
)

CREATE TABLE posts(
  tag_ids INT[] REFERENCES tags  (id),
);
class Tag
  include Core::Schema

  schema :tags do
    primary_key :id
    reference :posts, Array(Post), foreign_keys: :tag_ids
    field :content, String
  end
end

class Post
  include Core::Schema
  include Core::Query

  schema :posts do
    reference :tags, Array(Tag), keys: :tag_ids
  end
end

Post.join(:tags, select: nil).where("tags.content": "foo")
# => SELECT posts.* FROM posts JOIN tags ON posts.tag_ids @> tags.id WHERE tags.content = ?

@vladfaust vladfaust self-assigned this May 30, 2018

@vladfaust vladfaust closed this in 226b92c Sep 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.