質問編集履歴

6

2020/02/20 14:41

投稿

shori0128
shori0128

スコア29

test CHANGED
File without changes
test CHANGED
@@ -14,9 +14,9 @@
14
14
 
15
15
  A.name,
16
16
 
17
- B_DASH.id,
17
+ B_DASH.id as b_id,
18
18
 
19
- B_DASH.name,
19
+ B_DASH.name as b_name,
20
20
 
21
21
  B_DASH.owner_id
22
22
 

5

2020/02/20 14:41

投稿

shori0128
shori0128

スコア29

test CHANGED
File without changes
test CHANGED
@@ -96,4 +96,8 @@
96
96
 
97
97
 
98
98
 
99
+ A.left_join(B_DASH)のような記述ができればいいのですが、そういった記述はサポートされていないようですし、クエリをゴリゴリ書くしかないのかと、半分諦めているところです。。
100
+
101
+
102
+
99
103
  皆様、お忙しいところ大変恐縮ですが、ご教示いただけると助かります。

4

2020/02/20 13:24

投稿

shori0128
shori0128

スコア29

test CHANGED
File without changes
test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
  ) B_DASH
48
48
 
49
- ON A.ID = B.A_ID
49
+ ON A.ID = B_DASH.A_ID
50
50
 
51
51
  WHERE
52
52
 

3

2020/02/20 13:07

投稿

shori0128
shori0128

スコア29

test CHANGED
File without changes
test CHANGED
@@ -78,13 +78,13 @@
78
78
 
79
79
  以下の記事を参考にAのhas_manyにowner_idの絞込を付加することも考えたのですが、引数が渡せないため断念しました。
80
80
 
81
- [リンク内容](https://sharpknock.com/posts/programming/scoped-association.html)
81
+ [【Rails】結合先のテーブルで条件つけたいけど, 結合元のレコードは全部欲しいってときはScoped Association](https://sharpknock.com/posts/programming/scoped-association.html)
82
82
 
83
83
 
84
84
 
85
85
  sessionをモデルから参照することも考えたのですが、以下の記事では推奨されていないため、その方法も断念しました。
86
86
 
87
- [ク内容](https://www.izumisy.work/entry/2017/06/18/160051)
87
+ [モデルの中でセッショを使う](https://www.izumisy.work/entry/2017/06/18/160051)
88
88
 
89
89
 
90
90
 

2

2020/02/20 12:44

投稿

shori0128
shori0128

スコア29

test CHANGED
File without changes
test CHANGED
@@ -78,13 +78,13 @@
78
78
 
79
79
  以下の記事を参考にAのhas_manyにowner_idの絞込を付加することも考えたのですが、引数が渡せないため断念しました。
80
80
 
81
- https://sharpknock.com/posts/programming/scoped-association.html
81
+ [リンク内容](https://sharpknock.com/posts/programming/scoped-association.html)
82
82
 
83
83
 
84
84
 
85
85
  sessionをモデルから参照することも考えたのですが、以下の記事では推奨されていないため、その方法も断念しました。
86
86
 
87
- https://www.izumisy.work/entry/2017/06/18/160051
87
+ [リンク内容](https://www.izumisy.work/entry/2017/06/18/160051)
88
88
 
89
89
 
90
90
 

1

誤字

2020/02/20 12:41

投稿

shori0128
shori0128

スコア29

test CHANGED
File without changes
test CHANGED
@@ -60,7 +60,7 @@
60
60
 
61
61
  Class A < ApplicationRecord
62
62
 
63
- has_many B_TABLE
63
+ has_many B
64
64
 
65
65
  end
66
66
 
@@ -68,7 +68,7 @@
68
68
 
69
69
  Class B < ApplicationRecord
70
70
 
71
- belongs_to A_TABLE
71
+ belongs_to A
72
72
 
73
73
  end
74
74