-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Option to disable foreign keys creation #3120
Option to disable foreign keys creation #3120
Comments
Adding @pleerock |
Yeah it can bring some issues. I would like to know what is the point of this feature request. |
Our DBA told us to remove all foreign keys for performance reasons and to ease sharding, clustering and online migrations. It's actually the second company I work for where this was requested, but it's my first time using TypeORM, so I had to fork and get rid of the line that creates the foreign keys. I actually don't see the point of enforcing them. It seems to me like it's up to the application to maintain consistency its own way or to use foreign keys where appropriate if desired, right? (The option is there if anyone wants to use them.) |
Think we can try to do it, but I'm not sure about all consequences |
That would be awesome. Maybe I can help if I find some free time. A bit over-worked right now ): |
Oh, this is what we discussed in the beginning #1031 |
This feature would let to have "soft" relations across databases in different hosts. That is really my requirement now. |
Maybe we should give user an option to choose whether to use a foreign key or not. |
Any news on this? Is it possible to disable it? |
This comment has been minimized.
This comment has been minimized.
I have had a similar problem. The issue I had is with my unit testing where I use synchronise. My production code would be fine, but TypeORM wants to put the FK on the wrong table. In the example below I put the relation on the stats table, not the channel table. In case it helps anyone else, I've just used @Entity('channel')
export class Channel {
@PrimaryGeneratedColumn()
public id: number;
// ...
public stats?: ChannelStats;
}
@Entity('channel_stats')
export class ChannelStats {
@PrimaryColumn()
public channel_id: number;
@Column({ unsigned, default: 0 })
public members: number;
}
// Then something like
const users = await connection
.getRepository(Channel)
.createQueryBuilder("c")
.leftJoinAndMapOne('c.stats', 'channel_stats', 's', 's.channel_id = c.id')
.getMany(); |
@alfaproject can you please share the changes you did? I am having some super weird issues atm and I think they might be related to the auto-creation of FKs. Thanks! |
Basically created a patch to comment out the method that creates the relations. I've stopped using the library, so can't remember the exact file, so you have to search for it. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
config with |
Our DBA told us to remove all foreign keys for performance reasons too. |
This comment has been minimized.
This comment has been minimized.
It could be useful in tests cases too. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The PR is still up? Happy to review it. |
we are sort of "constrained" in our schema as well by the enforcement of foreign key constraints. here's another (recent) Issue asking for a way to tell TypeORM not to auto-generate one |
I've added the #7112 PR but I don't have enough time to write the tests ATM, can someone assist me in that? |
This new option allows to create relation without using foreign keys Closes: typeorm#3120
Any update on this? I must use an old db which I need to disable the foreign key constraint. |
* Add relation option "createForeignKeyConstraints" * feat: add createForeignKeyConstraints relation option This new option allows to create relation without using foreign keys Closes: #3120 * test: add cases for createForeignKeyConstraints relation option * docs: createForeignKeyConstraints relation option * test: remove .only * chore: remove unused test files * test: add case checking if relation without foreign key works as expected * fix: register join columns for relation without foreign key Closes: #3120 Co-authored-by: Alexander Bolshakov <alexanderb@cubedmobile.com>
as a closing comment #7277 was merged to master (check releases for the needed version): you can now do this to disable the FK by
|
https://typeorm.io/#/relations-faq/avoid-foreign-key-constraint-creation: the doc, avoid foreign key constraint creation. |
Is there a way, that setting |
How can I do this when using EntitySchemas? Adding createForeignKeyConstraints:false to the relation definition does not seem to work (and the type does not have this property) |
Did someone found a way to do this? |
Issue type:
[x] question
[ ] bug report
[x] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[x]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
Is there a way to disable foreign keys creation? I searched a bit and couldn't find it.
If not, is there a chance such option can be implemented? Maybe I can give it a try if you point me in the right direction. (:
The text was updated successfully, but these errors were encountered: