anykeyh/clear

Example "has many through" not compiling.

Ash42Z opened this issue · 4 comments

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?

@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

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

maybe someone could post a working example.

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