clear icon indicating copy to clipboard operation
clear copied to clipboard

Example "has many through" not compiling.

Open Ash42Z opened this issue 4 years ago • 4 comments
trafficstars

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 avatar Apr 20 '21 20:04 Ash42Z

@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

matthewmcgarvey avatar Apr 24 '21 20:04 matthewmcgarvey

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 avatar May 25 '21 13:05 kingsleyh

maybe someone could post a working example.

kingsleyh avatar May 25 '21 17:05 kingsleyh

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

Saipov avatar Jun 25 '21 20:06 Saipov