User Table
id| name  | email          | invited_by_id  
1 | jhon  | [email protected]  | null  
2 | sarah | [email protected] | 1  
3 | baby  | [email protected]  | 2  
As User table you'll see sarah's invited by jhon and baby's invited by sarah
Expect Result
id| name  | email         | invited_by_id | invited_by_name  
1 | jhon  | [email protected] | null          | null  
2 | sarah | [email protected]| 1             | jhon  
3 | baby  | [email protected] | 2             | sarah 
How to create select cmd or best way to get the result as my expect on rails active model ?
                        
user.rbor you can use
belongs_toand the inviter name can be got like below: