sql - Double relation to one table merged as one -


i try simplify example. i've got table called friendship 2 relations user (lets call them user1 , user2). retrieve alphabetical list of friends. can appear in user1 or in user2. way can know using unions:

select f.*     (select "user1"."name" "name"     "friendship" "friendship" left join "user" "user1"     on "friendship"."user1_id" = "requesteduser"."id"      , "user1"."id" != 'me'     ("friendship"."user2_id" = 'me')      union      select "user2"."name" "name"     "friendship" "friendship"         left join "user" "user2"          on "friendship"."user2_id" = "user2"."id"          , "user2"."id" != 'me'     ("friendship"."user1_id" = 'me')     ) f order "name" limit ?; 

is there easier way? or maybe there possibility in single select? know how in sequelize?

in sequelize should able user.getfriends() of users friends. if aliased associations outbound , inbound user.getinbound() , user.getoutbound().

sequelize automatically creates , names methods on instances allow associated models.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -