foreign-keys

Laravel 4 deleting multiple models related by foreign keys

给你一囗甜甜゛ 提交于 2019-12-24 21:10:06
问题 So I have three models and when when one of them dAgency is deleted delete-() I'd like all three to be deleted. The problem is that two of them are being deleted, while the top parent one DemDataSet isn't being deleted. Additionally, when I call: echo "<pre>", dd(dAgency::find(21)->DemographicReport()->DemDataSet()->get()), "</pre>"; I get this error: Call to undefined method Illuminate\Database\Query\Builder::DemDataSet() But when I try: echo "<pre>", dd(dAgency::find(21)->DemographicReport(

Android How to make self-relationship in ORMLite?

北慕城南 提交于 2019-12-24 20:42:03
问题 I have the following object that is a self-relationship, as follows: @DatabaseTable(tableName = "categoria") public class Categoria implements Serializable { @DatabaseField(generatedId = true) public int id; @DatabaseField(canBeNull = true, foreign = true) public Categoria pai; @DatabaseField(canBeNull = false, width = 50, unique = true) public String descricao; public Categoria() { } } When I do this: Categoria cat = new Categoria(); cat.pai = null; cat.descricao = "Comidas"; categoryDao

Django Foreign Key class not showing

最后都变了- 提交于 2019-12-24 19:29:26
问题 The goal is to have a dashboard show a list of users in your area. The list of users works and it shows the Username. The only issue is I can't get the users images (ideally just have 1st image) to show. There are no error messages currently. Just nothing appearing. models.py class Images(models.Model): image = models.ImageField(upload_to='profile_image', null=True, default='profile_image/none/no-img.png') user = models.ForeignKey(User, on_delete=models.CASCADE, null=False) class Profile

How to get data in an sql foreign key using asp.net entity framework?

為{幸葍}努か 提交于 2019-12-24 19:16:57
问题 I'm now trying to incorporate relational database in my project. Before the implementation of rdbms in my project, normally i would normally be able to access my desired value through this code: public static string guitar { get; set; } public static List<stringInstrumentItem> GetGuitarItems() { List<stringInstrumentItem> list2 = new List<stringInstrumentItem>(); MusicStoreDBEntities obj2 = new MusicStoreDBEntities(); list2 = (from g in obj2.stringInstrumentItems where g.brand == guitar

Structuring database relationships for tracking different variations of app settings

放肆的年华 提交于 2019-12-24 19:03:44
问题 An app I'm currently designing allows users to create custom competitive leagues (think of it kind of like fantasy sports) and each user can join different leagues and each league consists of multiple rounds where the users (hereafter referred to as Players) will compete and can earn points for different criteria/accomplishments established for each league. Here's some key info to note: Points are accrued across all the rounds during a league/season The custom point criteria/weight settings

What foreign keys to add in 1:N relationship - Logical Model

旧街凉风 提交于 2019-12-24 18:13:53
问题 I'm confused about marking down bidirectional 1:N relationship in a logical model. We have two tables: Employee and Department. Every employee "knows" what department he's working at and every department "knows" what employees work there - in other words a collection of Employee identifiers. From a formal point of view, do I mark this down by adding FK to both tables? |EMPLOYEE | |DEPARTMENT| |____________| |__________| |PK EMP_ID |>O------||-|PK DEPT_ID| |FK DEPT_ID | |FK EMP_ID | |NAME |

SQLite - How to delete parent row while keeping the child/children rows?

南笙酒味 提交于 2019-12-24 15:45:28
问题 I understand the concepts of PRAGMA foreign_key and of ON DELETE RESTRICT/NO ACTION , but I am facing a different kind of situation. I need to delete a parent row but keep the child row associated with it. For example: CREATE TABLE A(id, name); INSERT INTO A(id, name) VALUES (1, "Loreum"); CREATE TABLE B(id, id_A, name) FOREIGN KEY(id_A) REFERENCES A(id); INSERT INTO B(id, id_A, name) VALUES (1, 1, "Opium"); DELETE FROM A WHERE id = 1; I want to achieve this while keeping the child row intact

How to pass foreign key attributes down through a nested form in Rails 3

社会主义新天地 提交于 2019-12-24 15:25:11
问题 I have three models: class Client < ActiveRecord::Base has_many :balancesheets has_many :investment_assets, :through => :balancesheets class Balancesheet < ActiveRecord::Base belongs_to :client has_many :investment_assets, :dependent => :destroy accepts_nested_attributes_for :investment_assets, :allow_destroy => true class InvestmentAsset < ActiveRecord::Base belongs_to :balancesheet belongs_to :client I have two questions that have to do with the foreign key client_id. First, when I create a

Is it possible to create a foreign key constraint using “NOT IN” logic

旧街凉风 提交于 2019-12-24 13:33:57
问题 Is it possible to add a foreign key constraint on a table which will allow values which do NOT exist in another table? In the example below, both tables contain the field USER_ID. The constraint is that a customer and and an employee cannot have the same USER_ID value. I am very limited in adding new tables or altering one of the tables in any way. CUSTOMER -------------------------- USER_ID varchar2(10) EMPLOYEE -------------------------- USER_ID varchar2(10) I thought of a few workarounds,

Mysql and FK's Problem

冷暖自知 提交于 2019-12-24 11:40:13
问题 i'm having trouble with some tables here. i have this table: CREATE TABLE `smenuitem` ( `nome` VARCHAR(150) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci', `url` VARCHAR(150) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci', `tipo` CHAR(4) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci', `ordemmenu` INT(10) NULL DEFAULT NULL, `codparent` INT(10) UNSIGNED NOT NULL, `codmenuitem` INT(10) UNSIGNED NOT NULL, `codmodulo` INT(10) UNSIGNED NOT NULL, PRIMARY KEY (`codmodulo`, `codmenuitem`, `codmenuitem2`),