foreign-keys

How to set a collection-property with FKs?

浪子不回头ぞ 提交于 2019-12-09 06:56:00
问题 I have a Business and a Category model. Each Business has many Categories via an exposed collection ( Category is disregarding the Business entity). Now here is my controller-action: [HttpPost] [ValidateAntiForgeryToken] private ActionResult Save(Business business) { //Context is a lazy-loaded property that returns a reference to the DbContext //It's disposal is taken care of at the controller's Dispose override. foreach (var category in business.Categories) Context.Categories.Attach(category

MongoDB storing arrays of ObjectId's

让人想犯罪 __ 提交于 2019-12-09 05:08:45
问题 In my database I have to store an array of object ids. What should I use? Something like this: [ObjectId("50350e12a36feb1be6000364"), ObjectId("57350e12a37fef1be6000922"), ObjectId("10350e17d34ffb1be6200925")] or something like this: ["50350e12a36feb1be6000364", "57350e12a37fef1be6000922", "10350e17d34ffb1be6200925"] I could save space with the second, and then cast to ObjectId , but am I loosing anything by using this approach? Do ObjectId s behave like foreign keys in relational databases?

sql:need to change constraint on rename table?

瘦欲@ 提交于 2019-12-09 04:51:51
问题 i have change name of table through procedure sp_rename.Do i need to change fk constraint of child table? 回答1: Constraints and indexes will be automatically renamed, but you will need to manually do rename work in stored procedures, triggers, user-defined functions, and views that reference the table. See the documentation on MSDN. 回答2: No, the table name change will have also updated the apporpriate Metadata in the system catalogs and so the constraint will still be referencing the correct

java hibernate entity: allow to set related object both by id and object itself

落花浮王杯 提交于 2019-12-09 04:41:09
问题 I've got a following Java class which is also a Hibernate entity: @Entity @Table(name = "category") public class Category { @ManyToOne @JoinColumn(name="parent_id") private Category parent; public Category getParent() { return parent; } public void setParent(Category parent) { this.parent = parent; } The category represents a node in a category tree. I'm implementing a webservice which allows to CRUD categories. For instance, the interface has the ability to create a category tree node and it

Schema specified is not valid. Errors: The relationship was not loaded because the type is not available

廉价感情. 提交于 2019-12-09 04:30:47
问题 I wish to reference the OrderAddress model twice in my Order model; once as a ShippingAddress and once as a BillingAdress . On the other side, I want my OrderAddress model to have a list of OrderAddresses . OrderAddress Model public enum AddressType { Billing, Shipping, Contact } public class OrderAddress : BaseModel { public AddressType AddressType { get; set; } public bool IsPrimary { get; set; } public string Address { get; set; } public string CityStateZip { get; set; } public string

sqlite3 “foreign key constraint failed”

為{幸葍}努か 提交于 2019-12-09 02:53:15
问题 I've set up two tables: CREATE TABLE A ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT ); CREATE TABLE B ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, id2 INTEGER, book TEXT, FOREIGN KEY(id2) REFERENCES A(id) ); After I insert data into A , it looks like this: 1 John 2 Amy 3 Peter After I insert data into B , it looks like this: 1 1 Lord of the Rings 2 1 Catch 22 3 2 Sum of All Fears 4 3 Hunt for Red October I then execute the following statement: delete from a where id=1; I get

How to delete data from multiple tables?

旧城冷巷雨未停 提交于 2019-12-09 02:09:06
问题 I have these tables: event (evt_id, evt_code, reg_id) magnitude (mag_id, evt_id, value) trace (trace_id, pt_id) point (pt_id, evt_id) I want to delete all rows from all tables related to evt_id=1139 . How do I do it? 回答1: If you have control over your schema, I would make the schema use cascading deletes. From the article (the more pertinent portion translated for your example) CREATE TABLE point ( pt_id integer PRIMARY KEY, evt_id integer REFERENCES event ON DELETE CASCADE ) If you have

MySQL composite unique on FK's

六眼飞鱼酱① 提交于 2019-12-09 01:45:39
问题 I want to implement the following constraints in mysql: create table TypeMapping( ... constraint unique(server_id,type_id), constraint foreign key(server_id) references Server(id), constraint foreign key(type_id) references Type(id) ); This throws a 'ERROR 1062 (23000): Duplicate entry '3-4' for key 'server_id'' when I issue an insert/update that would break the constraint. Is this type of constraint even possible? If so how? Thank you. 回答1: Yes, that is perfectly valid. Make sure you

Yii - how can I search by a column from foreign/related key on admin page?

元气小坏坏 提交于 2019-12-09 00:18:47
问题 In my database, I have two tables, manufacturer and plastic: CREATE TABLE `manufacturer` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(64) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 CREATE TABLE `plastic` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL DEFAULT '', `manufacturer_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`,`manufacturer_id`), KEY `manufacturer_id` (`manufacturer_id`),

Manipulating Data in Django's Admin Panel on Save

浪子不回头ぞ 提交于 2019-12-08 22:40:58
问题 Ok, so here's the skinny: # models.py class Article( models.Model ): title = models.CharField( max_length = 255 ) author = models.ForeignKey( User ) published_at = models.DateTimeField( auto_now_add = True ) body = models.TextField( ) def __unicode__( self ): return self.title # admin.py from hpccoe.news.models import Article from django.contrib import admin from django import forms from django.forms import widgets class ArticleAdminForm( forms.ModelForm ): title = forms.CharField( max_length