Skip to content

Instantly share code, notes, and snippets.

@chyzwar
Created January 12, 2017 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chyzwar/a8aaaa0e0532a650ea68a4992ac94d00 to your computer and use it in GitHub Desktop.
Save chyzwar/a8aaaa0e0532a650ea68a4992ac94d00 to your computer and use it in GitHub Desktop.
Error in src/tribe-users.cr:8: while requiring "./routes/*"
require "./routes/*"
^
in src/routes/user.cr:1: while requiring "../models/*"
require "../models/*"
^
in src/models/post.cr:4: expanding macro
schema "posts" do
^~~~~~
in src/models/post.cr:4: expanding macro
schema "posts" do
^
in macro 'schema' /home/raziel/MyProjects/shadow-aspect/tribe-users/lib/crecto/src/crecto/schema.cr:52, line 22:
1. include Crecto::Schema::HasMany
2. include Crecto::Schema::HasOne
3. include Crecto::Schema::BelongsTo
4.
5. # macro constants
6. VALID_FIELD_TYPES = [String, Int64, Int32, Float32, Float64, Bool, Time, Int32 | Int64, Float32 | Float64]
7. VALID_FIELD_OPTIONS = [:primary_key, :virtual]
8. FIELDS = [] of NamedTuple(name: Symbol, type: String)
9.
10. # Class variables
11. @@table_name = "posts"
12. @@changeset_fields = [] of Symbol
13. @@initial_values = {} of Symbol => DbValue
14.
15. # Instance properties
16. property initial_values : Hash(Symbol, DbValue)?
17.
18. #<loc:push>begin #<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",5,5>field(#<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",5,11>:user_id, #<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",5,21>PkValue)
19. #<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",6,5>belongs_to(#<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",6,16>:user)
20. end#<loc:pop>
21.
> 22. setup
23.
expanding macro
in macro 'schema' /home/raziel/MyProjects/shadow-aspect/tribe-users/lib/crecto/src/crecto/schema.cr:52, line 22:
1. include Crecto::Schema::HasMany
2. include Crecto::Schema::HasOne
3. include Crecto::Schema::BelongsTo
4.
5. # macro constants
6. VALID_FIELD_TYPES = [String, Int64, Int32, Float32, Float64, Bool, Time, Int32 | Int64, Float32 | Float64]
7. VALID_FIELD_OPTIONS = [:primary_key, :virtual]
8. FIELDS = [] of NamedTuple(name: Symbol, type: String)
9.
10. # Class variables
11. @@table_name = "posts"
12. @@changeset_fields = [] of Symbol
13. @@initial_values = {} of Symbol => DbValue
14.
15. # Instance properties
16. property initial_values : Hash(Symbol, DbValue)?
17.
18. #<loc:push>begin #<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",5,5>field(#<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",5,11>:user_id, #<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",5,21>PkValue)
19. #<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",6,5>belongs_to(#<loc:"/home/raziel/MyProjects/shadow-aspect/tribe-users/src/models/post.cr",6,16>:user)
20. end#<loc:pop>
21.
> 22. setup
23.
expanding macro
in macro 'setup' /home/raziel/MyProjects/shadow-aspect/tribe-users/lib/crecto/src/crecto/schema.cr:125, line 15:
1. def initialize
2. end
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
> 15. DB.mapping({ user_id: {type: PkValue, nilable: true}, id: {type: DbBigInt, nilable: true}, created_at: {type: Time, nilable: true}, updated_at: {type: Time, nilable: true} })
16. JSON.mapping({ user_id: {type: PkValue, nilable: true}, id: {type: DbBigInt, nilable: true}, created_at: {type: Time, nilable: true}, updated_at: {type: Time, nilable: true} })
17.
18. # Builds a hash from all `FIELDS` defined
19. def to_query_hash
20. query_hash = {} of Symbol => DbValue
21.
22.
23. if self.user_id && @@changeset_fields.includes?(:user_id)
24. query_hash[:user_id] = self.user_id
25. query_hash[:user_id] = query_hash[:user_id].as(Time).to_utc if query_hash[:user_id].is_a?(Time)
26. end
27.
28.
29.
30. query_hash[:created_at] = self.created_at.nil? ? nil : self.created_at.as(Time).to_utc
31.
32.
33.
34. query_hash[:updated_at] = self.updated_at.nil? ? nil : self.updated_at.as(Time).to_utc
35.
36.
37. query_hash
38. end
39.
40. # Returns the value of the primary key field
41. def pkey_value
42. self.id.as(PkeyValue)
43. end
44.
45. def update_primary_key(val)
46. self.id = val
47. end
48.
49. def updated_at_value
50. self.updated_at
51. end
52.
53. def created_at_value
54. self.created_at
55. end
56.
57. def updated_at_to_now
58.
59. self.updated_at = Time.utc_now
60.
61. end
62.
63. def created_at_to_now
64.
65. self.created_at = Time.utc_now
66.
67. end
68.
69. # Return the primary key field as a String
70. def self.primary_key_field
71. PRIMARY_KEY_FIELD
72. end
73.
74. # Return the primary key field as a Symbol
75. def self.primary_key_field_symbol
76. PRIMARY_KEY_FIELD_SYMBOL
77. end
78.
79. def self.created_at_field
80. CREATED_AT_FIELD
81. end
82.
83. def self.updated_at_field
84. UPDATED_AT_FIELD
85. end
86.
87. # Class method to get the `changeset_fields`
88. def self.changeset_fields
89. @@changeset_fields
90. end
91.
92. # Class method to get the table name
93. def self.table_name
94. @@table_name
95. end
96.
97. # Get the Class for the assocation name
98. # i.e. :posts => Post
99. def self.klass_for_association(association : Symbol)
100. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:klass]
101. end
102.
103. # Get the foreign key for the association
104. # i.e. :posts => :user_id
105. def self.foreign_key_for_association(association : Symbol) : Symbol
106. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:foreign_key]
107. end
108.
109. def self.foreign_key_for_association(klass : Crecto::Model.class)
110. ASSOCIATIONS.select{|a| a[:klass] == klass && a[:this_klass] == self}.first[:foreign_key]
111. end
112.
113. # Get the foreign key value from the relation object
114. # i.e. :posts, post => post.user_id
115. def self.foreign_key_value_for_association(association : Symbol, item)
116. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:foreign_key_value].call(item).as(PkeyValue)
117. end
118.
119. # Set the value for the association
120. # i.e. :posts, user, [posts] => user.posts = [posts]
121. def self.set_value_for_association(association : Symbol, item, items)
122. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:set_association].call(item, items)
123. end
124.
125. # Get the association type for the association
126. # i.e. :posts => :has_many
127. def self.association_type_for_association(association : Symbol)
128. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:association_type]
129. end
130.
131. # Get the through association symbol
132. # i.e. :posts => :user_posts (if has_many through)
133. def self.through_key_for_association(association : Symbol) : Symbol?
134. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:through]
135. end
136.
137.
expanding macro
in macro 'setup' /home/raziel/MyProjects/shadow-aspect/tribe-users/lib/crecto/src/crecto/schema.cr:125, line 15:
1. def initialize
2. end
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
> 15. DB.mapping({ user_id: {type: PkValue, nilable: true}, id: {type: DbBigInt, nilable: true}, created_at: {type: Time, nilable: true}, updated_at: {type: Time, nilable: true} })
16. JSON.mapping({ user_id: {type: PkValue, nilable: true}, id: {type: DbBigInt, nilable: true}, created_at: {type: Time, nilable: true}, updated_at: {type: Time, nilable: true} })
17.
18. # Builds a hash from all `FIELDS` defined
19. def to_query_hash
20. query_hash = {} of Symbol => DbValue
21.
22.
23. if self.user_id && @@changeset_fields.includes?(:user_id)
24. query_hash[:user_id] = self.user_id
25. query_hash[:user_id] = query_hash[:user_id].as(Time).to_utc if query_hash[:user_id].is_a?(Time)
26. end
27.
28.
29.
30. query_hash[:created_at] = self.created_at.nil? ? nil : self.created_at.as(Time).to_utc
31.
32.
33.
34. query_hash[:updated_at] = self.updated_at.nil? ? nil : self.updated_at.as(Time).to_utc
35.
36.
37. query_hash
38. end
39.
40. # Returns the value of the primary key field
41. def pkey_value
42. self.id.as(PkeyValue)
43. end
44.
45. def update_primary_key(val)
46. self.id = val
47. end
48.
49. def updated_at_value
50. self.updated_at
51. end
52.
53. def created_at_value
54. self.created_at
55. end
56.
57. def updated_at_to_now
58.
59. self.updated_at = Time.utc_now
60.
61. end
62.
63. def created_at_to_now
64.
65. self.created_at = Time.utc_now
66.
67. end
68.
69. # Return the primary key field as a String
70. def self.primary_key_field
71. PRIMARY_KEY_FIELD
72. end
73.
74. # Return the primary key field as a Symbol
75. def self.primary_key_field_symbol
76. PRIMARY_KEY_FIELD_SYMBOL
77. end
78.
79. def self.created_at_field
80. CREATED_AT_FIELD
81. end
82.
83. def self.updated_at_field
84. UPDATED_AT_FIELD
85. end
86.
87. # Class method to get the `changeset_fields`
88. def self.changeset_fields
89. @@changeset_fields
90. end
91.
92. # Class method to get the table name
93. def self.table_name
94. @@table_name
95. end
96.
97. # Get the Class for the assocation name
98. # i.e. :posts => Post
99. def self.klass_for_association(association : Symbol)
100. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:klass]
101. end
102.
103. # Get the foreign key for the association
104. # i.e. :posts => :user_id
105. def self.foreign_key_for_association(association : Symbol) : Symbol
106. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:foreign_key]
107. end
108.
109. def self.foreign_key_for_association(klass : Crecto::Model.class)
110. ASSOCIATIONS.select{|a| a[:klass] == klass && a[:this_klass] == self}.first[:foreign_key]
111. end
112.
113. # Get the foreign key value from the relation object
114. # i.e. :posts, post => post.user_id
115. def self.foreign_key_value_for_association(association : Symbol, item)
116. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:foreign_key_value].call(item).as(PkeyValue)
117. end
118.
119. # Set the value for the association
120. # i.e. :posts, user, [posts] => user.posts = [posts]
121. def self.set_value_for_association(association : Symbol, item, items)
122. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:set_association].call(item, items)
123. end
124.
125. # Get the association type for the association
126. # i.e. :posts => :has_many
127. def self.association_type_for_association(association : Symbol)
128. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:association_type]
129. end
130.
131. # Get the through association symbol
132. # i.e. :posts => :user_posts (if has_many through)
133. def self.through_key_for_association(association : Symbol) : Symbol?
134. ASSOCIATIONS.select{|a| a[:key] == association && a[:this_klass] == self}.first[:through]
135. end
136.
137.
expanding macro
in macro 'mapping' /home/raziel/MyProjects/shadow-aspect/tribe-users/lib/db/src/db/mapping.cr:60, line 14:
1. include ::DB::Mappable
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
> 14. @user_id : PkValue ?
15.
16. def user_id=(_user_id : PkValue ?)
17. @user_id = _user_id
18. end
19.
20. def user_id
21. @user_id
22. end
23.
24. @id : DbBigInt ?
25.
26. def id=(_id : DbBigInt ?)
27. @id = _id
28. end
29.
30. def id
31. @id
32. end
33.
34. @created_at : Time ?
35.
36. def created_at=(_created_at : Time ?)
37. @created_at = _created_at
38. end
39.
40. def created_at
41. @created_at
42. end
43.
44. @updated_at : Time ?
45.
46. def updated_at=(_updated_at : Time ?)
47. @updated_at = _updated_at
48. end
49.
50. def updated_at
51. @updated_at
52. end
53.
54.
55. def self.from_rs(__temp_49 : ::DB::ResultSet)
56. __temp_50 = Array(self).new
57. __temp_49.each do
58. __temp_50 << self.new(__temp_49)
59. end
60. __temp_50
61. end
62.
63. def initialize(__temp_49 : ::DB::ResultSet)
64.
65. __temp_51 = nil
66. __temp_52 = false
67.
68. __temp_53 = nil
69. __temp_54 = false
70.
71. __temp_55 = nil
72. __temp_56 = false
73.
74. __temp_57 = nil
75. __temp_58 = false
76.
77.
78. __temp_49.each_column do |col_name|
79. case col_name
80.
81. when "user_id"
82. __temp_52 = true
83. __temp_51 =
84.
85. __temp_49.read(Union(PkValue | Nil))
86.
87.
88. when "id"
89. __temp_54 = true
90. __temp_53 =
91.
92. __temp_49.read(Union(DbBigInt | Nil))
93.
94.
95. when "created_at"
96. __temp_56 = true
97. __temp_55 =
98.
99. __temp_49.read(Union(Time | Nil))
100.
101.
102. when "updated_at"
103. __temp_58 = true
104. __temp_57 =
105.
106. __temp_49.read(Union(Time | Nil))
107.
108.
109. else
110.
111. raise ::DB::MappingException.new("unknown result set attribute: #{col_name}")
112.
113. end
114. end
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129. @user_id = __temp_51
130.
131.
132.
133.
134.
135. @id = __temp_53
136.
137.
138.
139.
140.
141. @created_at = __temp_55
142.
143.
144.
145.
146.
147. @updated_at = __temp_57
148.
149.
150.
151. end
152.
undefined constant PkValue (did you mean 'Value')
🤖 Compile time errors detected. SentryBot shutting down...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment