How to get the results of both tables in a join or include in rails -
i have 2 tables per diagram.
i want write query give me users associated relationships. userid in relationship table user_id
i have tried
relationship.includes(:user) but gives me results of relationship table,
relationship.joins(:user) which same

there records in both tables , can see railroady diagram associations correctly set up. correct syntax this?
you can try this.
user.joins("inner join relationships on users.id = relationships.userid").select("users.id, users.name, relationships.useeid, relationships.followsid") or
user.joins("inner join relationships on users.id = relationships.userid").select("users.*, relationships.*") to convert result json can try following.
result = user.joins("inner join relationships on users.id = relationships.userid").select("users.*, relationships.*") result = result.to_json
Comments
Post a Comment