1
votes

Is it possible to index table A ID to table B userId in postgreSQL ? So i would join 2 tables by id or something like that.

to better explain my question here is an example of mongoDB and mongoose:

const Billing = new Schema({
  account:Number,
  user: {
    type: Schema.Types.ObjectId,
    ref: 'user',
    required: true
  }
});
// later in the code i can do something like 
Billing.findOne().populate('user');

that will create a virtual relationship between billing to user.

can something like that be done with postgreSQL

I am using sequelize ORM.

1
Pretty sure everything is explained here: docs.sequelizejs.com/en/latest/docs/associationsThomas Ruiz
I am reading this right now too. did not see this before but as i wrote the question i though of searching for association.Neta Meta

1 Answers

0
votes

sound like you're talking about foreign keys http://www.postgresql.org/docs/8.3/static/tutorial-fk.html

In your case it should be something like:

create table B (
  userid varchar(80) primary key,
  <other fields>
);
create table A (
  id varchar(80) references B(userid),
  <other fields>
);

the type can be different as you need