Questions tagged [database-relations]

A relation is a data structure which consists of a heading and an unordered set of tuples which share the same type.

A relation is a data structure which consists of a heading and an unordered set of tuples which share the same type.

When Edgar F. Codd invented the relational model, he generalized the concept of binary relation (mathematical relation) to n-ary relation. Relation is a fundamental concept in relational model.

  • A relation has zero or more tuples.
  • A relation value is an instance of a relation.
  • A relation variable (relvar) is a variable which has a relation value.

In some contexts, relation means relation variable. In other contexts, relation means relation value.

In SQL, a database language for relational databases, a relation variable is called a table. Relational model concepts including relation

A relation value, which is assigned to a certain relation variable, is time-varying. By using a Data Definition Language (DDL), it is able to define relation variables.

  • A heading is the unordered set of certain attributes (columns). A heading has zero or more attributes.
  • A body is the unordered set of tuples, which constitutes a relation value. In other words, a relation value consists of a heading and a body.
  • A tuple is a data structure which consists of the unordered set of zero or more attributes.
  • An attribute (column) is a pair of its attribute name and domain name. Domain can be considered data type, or simply, type.
  • An attribute has an attribute value which conforms to its domain. An attribute value is a scalar value or a more complex structured value.
  • The degree of a relation is the number of attributes which constitute a heading. The degree of a relation value is zero or more integer. An n-ary relation is a relation value in which its degree is n.
  • The cardinality of a relation is the number of tuples which constitutes a relation value. The cardinality of a relation value is zero or more integer.

There are no duplicate tuples in a relation value. A candidate key is a certain minimal set of one or more attributes that can uniquely identify individual tuples in a relation value.

319 questions
0
votes
2 answers

Doctrine toarray does not convert relations

I followed doctrine documnetation to get started. Here is the documentation. My code is $User = Doctrine_Core::getTable("User")->find(1); when I access relations by $User->Phonenumbers, it works. When I convert User object to array by using…
Moon
  • 22,195
  • 68
  • 188
  • 269
0
votes
2 answers

Laravel and relationships

I have created a few tables like so, News (id, news_titles_id, create_time) NewsTitles (id, name) Now for my Models: class News extends Eloquent { protected $table = 'News'; public function title() { return…
John
  • 123
  • 9
0
votes
1 answer

MySQL require multiple values on same column

I have a few tables with some (example) values: people ---------------------------------- | id | name | ---------------------------------- | 1 | Steve Jobs | | 2 | Bill Gates | | 3 | Linus…
0
votes
1 answer

MVC dropdownlist with values from the database

Based on https://mvcmusicstore.codeplex.com/ trying to get a drop down list of attributes in the Details album before buying. I created a table with a map of attributes and table with attributes. In principle, the product has to refer to the map of…
user3128303
  • 747
  • 1
  • 11
  • 26
0
votes
1 answer

Eloquent ORM Laravel relations

In Laravel, I have two tables: books table has two fields( id , name ) users has three fields( id , name, book_id ) How I can get users that read more than five books?
phper
  • 181
  • 2
  • 12
0
votes
3 answers

ruby on rails force a has_many relationship, at least one

Below is my create function for my reviews controller. Basically the issue I have is that if a venue is left blank, and the artist isn't, an artist object is still created and a concert object is not. How do I prevent the artist from being created…
parameter
  • 894
  • 2
  • 18
  • 35
0
votes
2 answers

Checking if instance of model already exists with certain paremeters

In my application I want to check to see whether or not a concert model exists with the same artist and date fields as a review model. If It does I want to add the review to the concert, if not then I want to create a new concert and review, because…
0
votes
1 answer

Custom subscribe action using mongoid on Rails 4

I'm trying to set up a subscribers/subscriptions (followers/following) relationship for my users with mongoDB. My question is how to access my subscribe method (in model) from the web using a button. I've set up the model with referenced n-n…
brownie3003
  • 538
  • 7
  • 16
0
votes
0 answers

Laravel Many To Many Relation and Model

I have the following trouble.. I want to create form with binding to model. My tables structure: Table "Pages" - id - isHidden - isDeleted Table "Contents" - id - title - content Table "Seo" - id - title - description - keywords Table…
lieroes
  • 674
  • 2
  • 12
  • 29
0
votes
1 answer

@ManagedBean issues getting relational data

I have this weird problem that throws not really useful errors. I'm trying to display data from Entity Bean in Primefaces table. I have two projects, one for front end, other one for backend. Thing is, the Entity Bean has @OneToMany and @ManyToOne…
ptrdom
  • 100
  • 9
0
votes
1 answer

Does CakePhp recursively pull back data?

So i have the following database situation: Event has a link to many TroupeInfo, TroupeInfo has a sing link to TrouperCategory As a test I created a controller for TroupeInfo, and it pulls back the correct trouperCategory entry, however if I run the…
nagates
  • 620
  • 13
  • 40
0
votes
1 answer

sql, define Separate relation to target table or get by joins

We're working on a CMS project with EF and MVC. We've Recently encountered a problem, Please consider these tables: Applications Entities ProductsCategories Products Relations are in this order:…
0
votes
1 answer

Yii how to set HAS_ONE relation where pk in one of two columns of related model?

I have a PairModel pair_id | first_item_id | second_item_id | And Item model item_id | some_common_item_fields Relations of pair looks like that: public function relations() { return array( 'relatedFirstItem' => array(self::BELONGS_TO,…
Max Zhuravlev
  • 324
  • 3
  • 13
0
votes
0 answers

Yii Framework: Model Relations on a condition

I have a User, Profile, Teacher, and Student models. Database looks as follows: In the relations function of my Teacher and Student models, I would like to have: 'profile' => array(self::HAS_ONE, 'Profile', 'user_id', 'condition' =>…
TechMafioso
  • 135
  • 4
  • 16
0
votes
1 answer

symfony2 two one-to-one relations in @ORM/Id field

I have three entities: 'Usuario', 'Estudiante' and 'Administrador'. 'Usuario' represents the users in the application, that can be 'Estudiante' or 'Administrador'. How can I relate this? I show you the three entities: Entity 'Usuario' /** *…
bamalu
  • 25
  • 2
  • 8