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

Example "has many through" not compiling. #215

Open
Ash42Z opened this issue Apr 20, 2021 · 4 comments
Open

Example "has many through" not compiling. #215

Ash42Z opened this issue Apr 20, 2021 · 4 comments

Comments

@Ash42Z
Copy link

Ash42Z commented Apr 20, 2021

I am running crystal 1.0.0 on linux. I set the clear dependency to branch: master.
Tried to compile this (Example from the tutorial):

require "clear"

class Post
  include Clear::Model

  primary_key

  column name : String
  column content : String?

  has_many tags : Tag, through: "post_tags"
end

class Tag
  include Clear::Model

  primary_key

  column name : String

  has_many tags : Post, through: "post_tags"
end

I got the following compile error:

Error: [has_many tags through: ...]: Cannot find the relation `post_tags` in model Post. Existing relations are: tags

Is this a bug or am I doing something wrong?

@matthewmcgarvey
Copy link

@Ash42Z I think you have a typo on the tag association has_many tags : Post but the main issue is that you're trying to go through a join table it appears. In order for that to work you have to define that model and define the associations in the Post and Tag models

@kingsleyh
Copy link

I'm having the same issue - however the documentation must be incorrect then as it does not mention having to do that on the example instructions: https://clear.gitbook.io/project/model/associations/has_many-through

@kingsleyh
Copy link

maybe someone could post a working example.

@Saipov
Copy link

Saipov commented Jun 25, 2021

Hi! Have you tried to repeat the example from the tests (spec)?
There are differences in the fixtures in the models clear/spec/model/relations/fixture.cr

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

4 participants