質問編集履歴

4

修正

2018/03/21 15:58

投稿

ruby_0ct
ruby_0ct

スコア57

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ```
12
12
 
13
- と書いても、userテーブルの中身だけしか取れません。
13
+ と書いても、Active Recordをみるとuserテーブルの中身だけしか取れません。
14
14
 
15
15
  どのようにすれば理想の結合結果になるのか教えていだけると幸いです。
16
16
 

3

修正

2018/03/21 15:58

投稿

ruby_0ct
ruby_0ct

スコア57

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,8 @@
1
1
  userテーブル **1対多** blogテーブル
2
2
 
3
3
  このような関係で```includes```し、以下のような理想の結合結果にしたいのですが、
4
+
5
+ user_controller.rb
4
6
 
5
7
  ```ここに言語を入力
6
8
 

2

質問の変更

2018/03/21 15:34

投稿

ruby_0ct
ruby_0ct

スコア57

test CHANGED
@@ -1 +1 @@
1
- Railsのカラムのバイト数制限limit 4エラ
1
+ Rails ブルが結合されない
test CHANGED
@@ -1,43 +1,79 @@
1
+ userテーブル **1対多** blogテーブル
2
+
1
- String型数字だけの値(21バイト)```123456789012345678901```を ```create``` カラムに登録したいのですが以下のようにバイト数制限エラーがてしまいま
3
+ このような関係で```includes```し、以下のような理想の結合結果したいのですが、
2
4
 
3
5
  ```ここに言語を入力
4
6
 
5
- ActiveModel::RangeError
7
+ User.includes(:blogs)
6
8
 
9
+ ```
10
+
11
+ と書いても、userテーブルの中身だけしか取れません。
12
+
13
+ どのようにすれば理想の結合結果になるのか教えていだけると幸いです。
14
+
15
+
16
+
17
+ 理想の結合結果
18
+
19
+ |id|title|user|
20
+
21
+ |:--|:--:|--:|
22
+
23
+ |1|カレーの作り方|taro|
24
+
25
+ |2|iPhone X買ってみた|jiro|
26
+
27
+
28
+
29
+ blogテーブル
30
+
31
+ |id|title|user_id|
32
+
33
+ |:--|:--:|--:|
34
+
35
+ |1|カレーの作り方|1|
36
+
37
+ |2|iPhone X買ってみた|2|
38
+
39
+
40
+
41
+ userテーブル
42
+
43
+ |id|username|
44
+
45
+ |:--|:--:|
46
+
47
+ |1|taro|
48
+
49
+ |2|jiro|
50
+
51
+
52
+
53
+ ### blog.rb
54
+
55
+ ```
56
+
7
- 123456789012345678901 is out of range for ActiveModel::Type::Integer with limit 4
57
+ class Blog < ApplicationRecord
58
+
59
+ belongs_to :user
60
+
61
+ end
8
62
 
9
63
  ```
10
64
 
11
65
 
12
66
 
13
- カラムの設定を30バイトに変更したり、
67
+ ### user.rb
14
68
 
15
69
  ```ここに言語を入力
16
70
 
17
- def change
71
+ class User < ApplicationRecord
18
72
 
19
- change_column :テーブル名, :カラム名, :string, limit: 30
73
+ has_many :blogs
20
74
 
21
75
  end
22
76
 
23
- ```
24
77
 
25
- 整数型の```integer```に変更してみたりしたのですが、
26
-
27
- ```ここに言語を入力
28
-
29
- def change
30
-
31
- change_column :テーブル名, :カラム名, :integer, limit: 30
32
-
33
- end
34
78
 
35
79
  ```
36
-
37
- 同様のエラーでした。
38
-
39
- カラムの設定を変更しても、同様のエラーということはデータベースの問題ではなく、Rails上の設定の問題かなと思うのですが、それらしき情報が出てこないので質問させていただきました。
40
-
41
-
42
-
43
- ご回答いただけると幸いです。

1

タイトル変更

2018/03/21 15:33

投稿

ruby_0ct
ruby_0ct

スコア57

test CHANGED
@@ -1 +1 @@
1
- Railsのカラムのバイト数制限limit 4を変更したい
1
+ Railsのカラムのバイト数制限limit 4エラー
test CHANGED
File without changes