relation

Relational Algebra - Cartesian Product vs Natural Join?

↘锁芯ラ 提交于 2019-12-09 11:24:49
问题 I am studying for exams and am failing to find a solid criteria by which I can determine if the Cartesian Product x is to be used or if Natural Join |X| is to be used. I had come up with a rough guide that: "If you need to project an attribute that has the same name as an attribute in the table to be joined you must use x and state the table names to be projected: tableA.colname1 = tableB.colname1 " This however doesn't follow some of the solutions in my notes and my lecturer seems to use x

Yii2 hasMany/via vs. hasMany/viaTable vs. find/joinWith

孤者浪人 提交于 2019-12-08 10:50:29
问题 I have a many to many relation in Yii2: RecipeUnit - IngredientWeight - Ingredient. In model RecipeUnit: public function getIngredientWeights() { return $this->hasMany(IngredientWeight::className(), ['recipe_unit_id' => 'id']); } public function getIngredients() { return $this->hasMany(Ingredient::className(), ['id' => 'ingredient_id']) ->via('ingredientWeights'); } Using the following code ActiveQuery generates two SQLs instead of one join, and it takes long time ( $model is a RecipeUnit

How relating two tables to show name row and not the id in mysql+pdo

可紊 提交于 2019-12-08 08:57:35
问题 I don't know how show the name of the row in table 2 instead of his id when show it results of table 1. Let me explain: I have this tables in innoDB: - PACIENTES(table name). * id (int) * nombre (varchar) * apellido (varchar) * pais (varchar) * departamento (varchar) * ciudad (varchar) - lista_paises(table name). * id (int) * opcion (varchar) - lista_departamento(table name). * id_departamento (int) * opcion (varchar) * relacion (int)-----relation with table lista_paises---- - MUNICIPIOS

Recurrence Relation: Finding Big O

烂漫一生 提交于 2019-12-06 20:32:32
I am trying to find the big O bound for the following recurrence relation: T(n) = T(n-1) + n^c, where c >= 1 is a constant So I've decided to solve this by using iteration: T(n) = T(n-1) + n^c T(n-1) = T(n-2) + (n-1)^c T(n) = T(n-2) + n^c + (n-1)^c T(n-2) = T(n-3) + (n-2)^c T(n) = T(n-3) + n^c + (n-1)^c + (n-2)^c T(n) = T(n-k) + n^c + (n-1)^c + .... + (n-k+1)^c Suppose k = n-1, then: T(n) = T(1) + n^c + (n-1)^c + (n-n+1+1)^c T(n) = n^c + (n-1)^c + 2^c + 1 I'm not sure if this is correct however, plus I would really appreciate some guidance as to how to derive Big O from this. Thanks a lot! Yes

How relating two tables to show name row and not the id in mysql+pdo

倾然丶 夕夏残阳落幕 提交于 2019-12-06 16:47:56
I don't know how show the name of the row in table 2 instead of his id when show it results of table 1. Let me explain: I have this tables in innoDB: - PACIENTES(table name). * id (int) * nombre (varchar) * apellido (varchar) * pais (varchar) * departamento (varchar) * ciudad (varchar) - lista_paises(table name). * id (int) * opcion (varchar) - lista_departamento(table name). * id_departamento (int) * opcion (varchar) * relacion (int)-----relation with table lista_paises---- - MUNICIPIOS(table name). * id_municipio (int) * id_departamento (int)-----relation with table lista_departamento---- *

asp.net mvc 4 one to many relationship (article - tags)

為{幸葍}努か 提交于 2019-12-06 15:16:20
问题 I am trying to create 1-M relationship (1-*) and I cannot make this work. I have Article model and ArticleTag model. Logically I want to have an article linked with many tags. In "non-model" way, I would make 2 tables according these two models. public class Article { public int ArticleID { get; set; } public string Title { get; set; } public DateTime Date { get; set; } public string Anotation { get; set; } public string Body { get; set; } public string SourceLink { get; set; } public virtual

Postgres JOIN with unnest

≯℡__Kan透↙ 提交于 2019-12-06 03:11:02
问题 Assume I have following tables: table: followers_arrays id | array --------+--------- 1 | {3,4,5} table: small_profiles id | username | pic --------+----------+------- 3 | aaaa | abcd 4 | bbbb | abcd 5 | cccc | abcd I would like to print followers_array with populated data from small_profiles using simple JOINs. At first, I'm using unnest function like this: SELECT id, unnest(followers_array) AS elem FROM followers_arrays And it gives me about right result: id | elem --------+-------- 1 | 3 1

What is the purpose of ActiveRecord::Relation#bind?

£可爱£侵袭症+ 提交于 2019-12-06 00:03:45
问题 Just out of curiosity - I was reading the docs of the Relation::QueryMethods module and found that method: def bind(value) relation = clone relation.bind_values += [value] relation end Does anyone know what is this? I tried to find by myself, but failed. UPDATE I tracked down usage of @bind_values to the bottomless depth of ActiveRecord::ConnectionAdapters - the values get passed on and on till low-level SQL statement executions. Seems that the individual adapters may use these. My guess is

How to use constant in the ON condition in Yii2 hasMany relation

大憨熊 提交于 2019-12-04 22:18:55
I try to create a polymorphic association, what is common in Rails but unfortunately not in Yii2. As part of the implementation I need to define the relation: public function getImages() { return $this->hasMany(RecipeImage::className(), ['imageable_id' => 'id', 'imageable_type' => 'Person']); } But this doesn't work, because 'Person' is treated as an attribute of the current model, but it is a constant (class name for the polymorphic association). If I try to use 'andWhere' it adds the condition of course in a WHERE clause instead of the ON clause, causing that only records with existing image

asp.net mvc 4 one to many relationship (article - tags)

守給你的承諾、 提交于 2019-12-04 21:37:38
I am trying to create 1-M relationship (1-*) and I cannot make this work. I have Article model and ArticleTag model. Logically I want to have an article linked with many tags. In "non-model" way, I would make 2 tables according these two models. public class Article { public int ArticleID { get; set; } public string Title { get; set; } public DateTime Date { get; set; } public string Anotation { get; set; } public string Body { get; set; } public string SourceLink { get; set; } public virtual ICollection<ArticleTag> ArticleTags { get; set; } } public class ArticleTag { public int ArticleID {