Questions tagged [relation]

A relation on sets S1, S2, ..., SN is any subset of S1 x S2 x ... x SN, where 'x' denotes the Cartesian product. In other words, a relation over N sets is any set of ordered N-tuples over the N sets.

A relation on sets S1, S2, ..., SN is any subset of S1 x S2 x ... x SN, where 'x' denotes the Cartesian product. In other words, a relation over N sets is any set of ordered N-tuples over the N sets.

1457 questions
285
votes
9 answers

How to return an empty ActiveRecord relation?

If I have a scope with a lambda and it takes an argument, depending on the value of the argument, I might know that there will not be any matches, but I still want to return a relation, not an empty array: scope :for_users, lambda { |users|…
dzajic
  • 3,062
  • 2
  • 15
  • 9
168
votes
8 answers

Laravel Eloquent Sum of relation's column

I've been working on a shopping cart application and now I've come to the following issue.. There is a User, a Product and a Cart object. The Cart table only contains the following columns: id, user_id, product_id and timestamps. The UserModel…
Admiral
  • 1,878
  • 2
  • 12
  • 17
160
votes
3 answers

SQL ON DELETE CASCADE, Which Way Does the Deletion Occur?

If I have two relations in a database, like this: CREATE TABLE Courses ( CourseID int NOT NULL PRIMARY KEY, Course VARCHAR(63) NOT NULL UNIQUE, Code CHAR(4) NOT NULL UNIQUE ); CREATE TABLE BookCourses ( EntryID int NOT NULL PRIMARY KEY, …
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
48
votes
3 answers

utf8_bin vs. utf_unicode_ci

My table Website Website_Name//column name Google Facebook Twitter Orkut Frype Skype Yahoo Wikipedia I i use utf8_bin collation then my query to search wikipedia in Website is Select Website_Name from Website where…
user1432124
46
votes
9 answers

How to find all the relations between all mysql tables?

How to find all the relations between all MySQL tables? If for example, I want to know the relation of tables in a database of having around 100 tables. Is there anyway to know this?
user3148861
  • 461
  • 1
  • 4
  • 3
43
votes
2 answers

Graphviz Dot, mix directed and undirected

For my application I need to represent simultaneously (on the same graph) two relations: one is simmetric, the other is not. Targets: Ideally the two relation should result in edges having different colors; For the symmetric relation I would like…
Dacav
  • 13,590
  • 11
  • 60
  • 87
33
votes
1 answer

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

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(), …
Tibor Nagy
  • 1,185
  • 1
  • 15
  • 28
31
votes
3 answers

Query records through its belongs_to relation in Rails

I have an Activities model, and they belong_to a Location How do i select all the activities whose location.country = Australia? (for example) Can I do this within a scope?
Will
  • 4,498
  • 2
  • 38
  • 65
19
votes
1 answer

Laravel Search Relationship

I have two models which are related. I am trying to do a search in Products and only display the actual search results instead of ALL products of the category in which the product was found. I DO NOT want to search for any categories, since the…
Hardist
  • 2,098
  • 11
  • 49
  • 85
19
votes
2 answers

In postgresql, what's the difference a "database" and a "relation"? ('error relation x does not exist', 'error database x already exists')

I see the juxtaposition of these two errors and, given the dearth of Google search results, had to ask. What is the difference and what do I need to be doing here? deploy=# GRANT SELECT ON angel_research_production TO angel_research; ERROR: …
boulder_ruby
  • 38,457
  • 9
  • 79
  • 100
18
votes
5 answers

Laravel Grouping by Eloquent Relationship

How can I group by relation? Example Sales::with('product_detail.product')->groupBy('product_name')->get() How can I get a result with eloquent code?
yudijohn
  • 1,248
  • 3
  • 19
  • 43
16
votes
2 answers

Implementing one-to-zero-or-one relation in SQL Server

I'm using Entity Framework 4.1 database first approach. I've used legacy database. In my edmx file which created entity classes based on tables in the legacy database, there is a one-to-zero-or-one association between some entities. Although I…
15
votes
4 answers

Many tables or rows, which one is more efficient in SQL?

I'm building a program that stores news headlines for companies and its timestamp from various sources. Let's say the number of company is 1000. It goes like Apple, Google, Microsoft.. etc. So I can think about two options. One table with numerous…
KimchiMan
  • 4,836
  • 6
  • 35
  • 41
14
votes
4 answers

AirPlay support, MPMoviePlayerController and MPVolumeView relation

I am developing an iPhone application that has support for video play. I am using MPMoviePlayerController with custom controls for playing the video. For this purpose I have set control style of MPMoviePlayerController to MPMovieControlStyleNone. I…
spd
  • 2,114
  • 1
  • 29
  • 54
14
votes
3 answers

Postgres JOIN with unnest

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 …
Rafal Wiliński
  • 2,240
  • 1
  • 21
  • 26
1
2 3
96 97