relational-database

Can I force Yii to use particular alias in generated SQL

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:09:49
问题 I'm retrieving my records using CActiveRecord with a with() statement: Probes::model()->with(array ( 'user', 'results', 'results.answer', 'survey', 'survey.questions' ))->findByPk($id) I wanted to use GROUP BY on question_id field of survey.questions relation, so I changed above to: 'survey.questions'=>array('group'=>'survey.questions.question_id'), This caused a SQL exception 1054 Unknown column . However, by analyzing attached SQL code: `questions`.`question_id` AS `t6_c2` I managed to find

More complex IF statements within MySQL query

浪尽此生 提交于 2019-12-12 04:07:23
问题 I asked a related question a week ago, but here's another problem I'm facing. I feel like such a noob, but I guess it's better to ask and learn than never learn. Here are my three tables: Fighters Table fighter_id, name Events Table event_id, event_name, event_date Fights Table fight_id, fighter_a, fighter_b, winner, method, event So in the fights table, fighter_a, fighter_b, and winner are integers that correspond to fighter_id in the Fighters table. I'm basically on a page retrieving data

Transform between relational database and graph-based database

北慕城南 提交于 2019-12-12 04:00:50
问题 I am aware that there are algorithms (and even tools) to transform relational databases (RDBMS) to Graph databases, and the other way around. I do have several questions that are a bit larger than that: Is there a common-practice working algorithm out there for such transformation, for example RDBMS => graph (or several)? Is this algorithm bijective? To be more precise: 2.1. Given said algorithm, is the transformation RDBMS => graph injective (one-to-one)? More plainly, can there be any two

IPad App pull and push relational data

给你一囗甜甜゛ 提交于 2019-12-12 03:40:35
问题 Im currently putting together a business app for an ipad. It will be talking to a Microsoft SQL server database. My question is what is the most efficient way to pull relational data over the line. One example is im showing a contact listing in the app. The contact record has a departmentID field (which is related to the department table) and a ContactTypeID field (which is related to the ContactType table). I am hoping that when the user first starts the app I will pull the department and

Am trying to categorise values using Ms Access

人走茶凉 提交于 2019-12-12 03:27:22
问题 I am trying to categorise values using Ms Access into three categories; lets say (less than 3500 to be low, from 35000 to 1,500,000 to be middle and greater than 1,500,000 to be Upper). Please help I am still a learner 回答1: Create a select query with all the fields you need using the simple query wizard, then open it in design view and add a new column and type in this text (use your numeric fields name between the square brackets, I called mine "number") category: IIf([number]<3500,1,IIf(

ForeignKey field with primary relationship

亡梦爱人 提交于 2019-12-12 03:23:48
问题 I have two tables in my database (django: models in my app) as follows: class Model1(models.Model): name = models.CharField() #etc.... class Model2(models.Model): link = models.ForeignKey(Model1) Each Model1 can have many instances of Model2 linked to it, but Model2 can only be linked to one Model1 - a basic one-to-many relationship. My problem is this: I need each Model1 to have a primary Model2 - that is, one of it's related Model2s needs to somehow be marked as "primary". These are my

Should one generate a unique id for each row in a database table that otherwise has no unique keys?

て烟熏妆下的殇ゞ 提交于 2019-12-12 03:22:04
问题 I'm designing a MySQL database for a startup working with patient medical records. I have several tables that can have no unique keys: medical conditions, allergies, family history, etc. For example the medications table might have fields patient_id , med_name , usage_dates , dosage , reason , etc. The only guaranteed unique key is all of the fields together. A web application can easily retrieve this data for a given patient by selecting for patient_id , but unless it is possible to save

Rails 4: can a child model belong_to two different parent models

落花浮王杯 提交于 2019-12-12 03:13:23
问题 In my initial Rails 4 app, I had the following models: User has_many :administrations has_many :calendars, through: :administrations has_many :comments Calendar has_many :administrations has_many :users, through: :administrations has_many :posts has_many :comments, through: :posts Administration belongs_to :user belongs_to :calendar Post belongs_to :calendar has_many :comments Comment belongs_to :post belongs_to :user I just added a new Ad model to the app: Ad belongs_to :calendar And now I

MVC with EF Relational Database Mapping

荒凉一梦 提交于 2019-12-12 03:00:33
问题 I have this error when I try to update my database to population my tables. PM> update-database No pending explicit migrations. Running Seed method. System.InvalidOperationException: Sequence contains no matching element at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate) at RecreationServicesTicketingSystem.Migrations.Configuration.Seed(IssueContext context) in C:\Users\jwan\Documents\Visual Studio 2012\Projects\RecreationServicesTicketingSystem

An image table to serve two foreign tables?

不打扰是莪最后的温柔 提交于 2019-12-12 02:57:55
问题 I have this image table , image_id image_title image_description image_source and I want this image table to associate with page table and sometimes with comment table page table, page_id ... ... comment table, comment_id ... ... Should I put the foreign key of page_id and comment_id in image table? image_id image_title image_description image_source page_id comment_id Or should I create a map table for each purpose? a map table for image and page image_id page_id and another map table for