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
4
votes
1 answer

Yii2 "has no relation named" at search model even the function it is defined in the main model

I am having a yii2 error : common\models\Book has no relation named "favorite". When I try to add: public function search($params) { $query = Book::find(); $query->joinWith(['author', 'profile', 'favorite']); In the book model I do have the…
open-ecommerce.org
  • 1,763
  • 1
  • 25
  • 41
4
votes
2 answers

How do I construct my model when it contains two relations to the same type of object?

I’m using Rails 4.2.3 I have a model with two relations to the same type of object, class MyObject < ActiveRecord::Base belongs_to :user has_many :my_object_times … has_one :my_object_time, foreign_key: :linked_my_object_time_id The column…
Dave
  • 15,639
  • 133
  • 442
  • 830
4
votes
2 answers

Laravel, many-to-many relationship to multiple models

Looking for a simple way of doing the following in Laravel 5. Imagine these models and interface Competition User Team Participant (Interface which User and Team implements) A competition will have a many-to-many relationship to is participants,…
4
votes
2 answers

select * from (select a,b,c ...) guaranteed order of result columns?

I recently had a comment in a code review: it's better to enumerate the fields explicitly. "select *" doesn't guarantee an order Is that true in this case with a query like select * from (select a,b,c ...)? I can't imagine a database engine that…
Eloff
  • 20,828
  • 17
  • 83
  • 112
4
votes
3 answers

how to remove a relation (pointer) in a Parse.Object without deleting the related Object?

I have a relation from the a model called thisDrive of class Drives in a column called lastDrive, which is also a Drive. Sometimes I need to delete this relation, so nothing is related (undefined). How can I remove the relation from a single drive…
otmezger
  • 10,410
  • 21
  • 64
  • 90
4
votes
1 answer

Get single item with particular value on hasMany relation Laravel

I have two tables: items ( id name description ) images ( id item_id number // 0 -> main image ; 1,2,3,4 ... -> gallery_image ) with this basic relation: #Item.php public function images() { return…
kurtko
  • 1,978
  • 4
  • 30
  • 47
4
votes
2 answers

ActiveRecord has_many through polymorphic has_many

It seems like rails still not support this type of relation and throws ActiveRecord::HasManyThroughAssociationPolymorphicThroughError error. What can I do to implement this kind of relation? I have following associations: Users 1..n…
atomAltera
  • 1,702
  • 2
  • 19
  • 38
4
votes
2 answers

Cannot infer instance (haskell error)

The following is defined in my assignment: type Rel a = Set (a,a) complR :: Ord a => Set a -> Rel a -> Rel a complR (Set xs) r = Set [(x,y) | x <- xs, y <- xs, not (inR r (x,y))] The set type can be called like this for example: (Set…
anon
4
votes
1 answer

Correct way in using Laravel 4 User model relations with Sentry 2 package

I'm trying to find out how to return the relations I set up for my User model when using Sentry 2. Normally, I have a user retrieved like this: $user = User::find(1); // get some relation return $user->profile->profile_name; However, now when I…
Marty
  • 463
  • 2
  • 6
  • 14
4
votes
1 answer

Laravel / Eloquent: Search for rows by value in polymorphed table

I'm stuck at the moment and hope someone can give me a hand. I'm using a polymorphic relation and want to search my database for rows that fulfill conditions in the "parent" and the "child" table. To get concrete, one small example. Given the…
MrSnoozles
  • 860
  • 8
  • 13
4
votes
2 answers

Accessing relations from templates with ember-data 1.0.0 beta

App.User = DS.Model.extend({ posts: DS.hasMany('post', {async: true}) }); App.Post = DS.Model.extend({ body: DS.attr(), user: DS.belongsTo('user') }); App.ProfileRoute = Ember.Route.extend({ model: function(params) { return…
Aminov Vali
  • 194
  • 1
  • 1
  • 7
4
votes
2 answers

Selecting a row if it has all related options in a related table

Given a table definition: Articles: art_id | name -------|-------------- 1 | article1 2 | article2 3 | article3 Tags: tag_id | description -------|-------------- 1 | Scientific 2 | Long 3 |…
Tomer W
  • 3,395
  • 2
  • 29
  • 44
4
votes
2 answers

How to override the default has_many condition for a relation in rails?

I would like to enter my own condition for a has_many relationship in my ActiveRecord model. I want my condition to override the default condition. Class User < ActiveRecord::Base has_many :notifs, :conditions => proc { "(notifs.user_id =…
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
4
votes
1 answer

Combine two ActiveRecord::Relation with OR, not AND, returning a Relation and not an Array to be able to paginate later

a and b are ActiveRecord::Relation objects which return the same type of objects(Micropost objects in this case) a.class => ActiveRecord::Relation b.class => ActiveRecord::Relation a.first => Micropost(...) b.first => Micropost(...) #They both…
ICTylor
  • 470
  • 4
  • 14
4
votes
1 answer

What is the advantage of relationships between tables in sql?

I made three tables. Table1=users.And the column names are userid (auto_increment) and username. Table2=hobbies. column names are hobbyid (auto_increment) and hobbyname. Table3=users_hobbies. column names are FK_userid and FK_hobbyid. Now whenever I…
Santosh
  • 1,871
  • 1
  • 19
  • 36