Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column method to SchemaBuilding functions #558

Closed
gaastonsr opened this issue Nov 12, 2014 · 1 comment
Closed

Add column method to SchemaBuilding functions #558

gaastonsr opened this issue Nov 12, 2014 · 1 comment

Comments

@gaastonsr
Copy link

Following up #488, it would be nice to have a column in the SchemaBuilding functions that references a column. The example proposed is that when you create a table with createTable that has columns referencing other tables, you need to be careful in the order you create your table to not receive error: relation "x" does not exist.

(Sometimes when two tables reference mutually it's impossible to do it this way, and you need to create your tables first and then do the wiring.)

With the current API the only way to do this is to create your columns after the table is created.

.table('accounts', function(table) {
    table.integer('user_id').unsigned().references('users.id');
})

When a more elegant solution would be to create your columns at the table creation time and then just do the wiring

.table('accounts', function(table) {
    table.column('user_id').references('users.id');
})

What do you think? I might do a PR for this.

@bendrucker
Copy link
Member

See #46. The column API is what I'd like to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants