foreign-keys

Rails updating multiple models on a single form

时光总嘲笑我的痴心妄想 提交于 2019-12-07 16:36:18
问题 Im writing a form which uses formtastic to manage the BusinessUnit model, however when creating a new BusinessUnit it also has to create a number of other record types. The associations between the models are as below: class BusinessUnit < ActiveRecord::Base has_many :business_unit_sites has_many :locations class BusinessUnitSite < ActiveRecord::Base belongs_to :site belongs_to :business_unit class Site < ActiveRecord::Base has_many :locations has_many :business_unit_sites class Location <

Change primary key value in Oracle

让人想犯罪 __ 提交于 2019-12-07 13:59:23
问题 Is there a way to change the value of a primary key which is referenced by another table as foreign key? 回答1: An easier alternative is to insert a new row and delete the old one. (Update any referencing rows in other tables before you do the delete) 回答2: There isn't an in-built UPDATE CASCADE if that's what you're after. You'd need to do something like disable any FK constraints; run UPDATE statements; re-enable the constraints. Note that updating Primary Keys is (usually always) a bad idea.

Rails Engines with problems in Foreign keys

亡梦爱人 提交于 2019-12-07 12:38:40
问题 I'm developing a rails engine and this is my gem.gemspec s.required_ruby_version = '>= 2.0.0' s.add_dependency 'rails', '>= 4.2.0' s.add_dependency 'enumerate_it' s.add_dependency 'slim-rails' s.add_dependency 'bootstrap-sass' s.add_dependency 'jquery-rails' s.add_development_dependency 'rdoc' s.add_development_dependency 'tomdoc' s.add_development_dependency 'sqlite3' s.add_development_dependency 'rspec-rails' s.add_development_dependency 'timecop' s.add_development_dependency 'shoulda

ASP.NET MVC 4 Multiple Foreign Keys Referencing Single Parent Entity

孤街浪徒 提交于 2019-12-07 11:58:44
问题 I am trying to develop an ASP.NET MVC 4 application where players can be rated according to their Offence, Defence and Assist skills. Offence, Defence and Assist are foreign keys on Player table referencing the same lookup table - Rating. I have the following parent entity: public class Rating { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<Player> Players { get; set; } } And child entity: public class Player { public int Id { get; set; } public

play framework - SQLite: Enable Foreign Key

假如想象 提交于 2019-12-07 11:30:28
I have a problem when using SQLite with play, SQLite documentation says that foreign keys are disabled by default, and need to be enabled with each connection . I am using SQLite with Ebean, in evolution I added this line: PRAGMA foreign_keys = ON; but It doesn't work, it only works when I open a connection from terminal or SQLite Client and execute that line ( PRAGMA foreign_keys = ON; ), I also tried this in the start of the app but with no luck: Ebean.getServer("mom").createSqlUpdate("PRAGMA foreign_keys = ON;").execute(); So, how to enable foreign keys? You cannot do this via an evolution,

Laravel migration : Remove onDelete('cascade') from existing foreign key

倖福魔咒の 提交于 2019-12-07 09:53:09
问题 I have created a migration like this : // ... $table->foreign('a')->references('b')->on('c')->onDelete('cascade'); // ... I want to remove the onDelete('cascade') in a new migration without breaking anything. How can I do that ? 回答1: You can try to remove the old foreign key and add then add a new one without onDelete : $table->dropForeign('tablename_a_foreign'); $table->foreign('a')->references('b')->on('c'); 回答2: To change a foreign key you must drop the foreign key and create it again.

why foreign key doesn't work in websql..?

断了今生、忘了曾经 提交于 2019-12-07 09:00:54
问题 i try to use foreign key in my app using web sql.. i test it in chrome.. no error.. but when i test with manual insert to table img (contain FK) i expect to fail.. but insert is still succes.. this is my code.. please help me.. tx.executeSql("PRAGMA foreign_keys = ON;"); tx.executeSql("CREATE TABLE IF NOT EXISTS img (ID INTEGER PRIMARY KEY ASC,imgID VARCHAR, image VARCHAR, FOREIGN KEY (imgID) REFERENCES trans (ID) )", []); i this case i try to use FK method for save my image name data and

Foreign Keys with SchemaExport in Fluent NHibernate using SQLite

杀马特。学长 韩版系。学妹 提交于 2019-12-07 06:15:39
问题 I am attempting to create a simple database application which keeps track of loans of various types of equipment using Fluent NHibernate and SQLite. However, when I try to generate the database structure with SchemaExport for use in unit testing, foreign keys for one-to-many relationships aren't created. Here is my Equipment entity: public virtual int Id { get; set; } public virtual EquipmentType Type { get; set; } public virtual int StockId { get; set; } And here are my mappings for

MySQL error when creating foreign key with Laravel migration

早过忘川 提交于 2019-12-07 05:42:06
问题 I have a Laravel application set up and I'm using Sentry 2 for user authentication. I have a model called Post along with the default sentry User table. I would like to have a user to have many posts, and a post to belong to a user. To reflect this in my database schema, I need to create a foreign key constraint between posts and users . The migration that I've written is the following: public function up() { Schema::table('posts', function(Blueprint $table) { $table->integer('user_id')-

How to increment (or reserve) IDENTITY value in SQL Server without inserting into table

≡放荡痞女 提交于 2019-12-07 05:09:26
问题 Is there a way to reserve or skip or increment value of identity column? I Have two tables joined in one-to-one relation ship. First one has IDENTITY PK column, and second one int PK (not IDENTITY). I used to insert in first, get ID and insert in second. And it works ok. Now I need to insert values in second table without inserting into first. Now, how to increment IDENTITY seed, so I can insert it into second table, but leave "hole" in ID's of first table? EDIT: More info This works: -- I