Add associations between users via invitations
This commit is contained in:
parent
e675970f4c
commit
30fb9805e5
@ -1,6 +1,7 @@
|
|||||||
class Invitation < ApplicationRecord
|
class Invitation < ApplicationRecord
|
||||||
# Relations
|
# Relations
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :invitee, class_name: "User", foreign_key: 'invited_user_id', optional: true
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
validates_presence_of :user
|
validates_presence_of :user
|
||||||
|
@ -3,6 +3,10 @@ class User < ApplicationRecord
|
|||||||
|
|
||||||
# Relations
|
# Relations
|
||||||
has_many :invitations, dependent: :destroy
|
has_many :invitations, dependent: :destroy
|
||||||
|
has_one :invitation, inverse_of: :invitee, foreign_key: 'invited_user_id'
|
||||||
|
has_one :inviter, through: :invitation, source: :user
|
||||||
|
has_many :invitees, through: :invitations
|
||||||
|
|
||||||
has_many :donations, dependent: :nullify
|
has_many :donations, dependent: :nullify
|
||||||
|
|
||||||
has_one :lndhub_user, class_name: "LndhubUser", inverse_of: "user",
|
has_one :lndhub_user, class_name: "LndhubUser", inverse_of: "user",
|
||||||
|
@ -38,8 +38,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="overflow-ellipsis font-mono"><%= invitation.token %></td>
|
<td class="overflow-ellipsis font-mono"><%= invitation.token %></td>
|
||||||
<td><%= invitation.used_at.strftime("%Y-%m-%d (%H:%M UTC)") %></td>
|
<td><%= invitation.used_at.strftime("%Y-%m-%d (%H:%M UTC)") %></td>
|
||||||
<td><%= invitation.user.address %></td>
|
<td><%= link_to invitation.user.address, admin_user_path(invitation.user.address), class: "ks-text-link" %></td>
|
||||||
<td><%= User.find(invitation.invited_user_id).address %></td>
|
<td><%= link_to invitation.invitee.address, admin_user_path(invitation.invitee.address), class: "ks-text-link" %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -19,7 +19,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Invited by</th>
|
<th>Invited by</th>
|
||||||
<td><%= @inviter ? link_to(@inviter.address, admin_user_path(@inviter.address), class: 'ks-text-link') : "—" %></td>
|
<td>
|
||||||
|
<% if @user.inviter %>
|
||||||
|
<%= link_to @user.inviter.address, admin_user_path(@user.inviter.address), class: 'ks-text-link' %>
|
||||||
|
<% else %>—<% end %>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user