Questions tagged [relationships]

Relationships refer to mappings between elements of one set to another set, such as one-to-one, one-to-many, many-to-many.

Relationships can be implicit or explicit depending upon the data model.

Types of relationships

References

832 questions
5
votes
1 answer

SQL Modeling Follower/Followed Relationships For Social Networking

I am building a social graph for my website. Users will create relationships (of the form follower/followed) where each party may independently follow the other. My users table looks like this: Users table - UserId (PK, Auto-incrementing…
Harper
  • 1,285
  • 3
  • 15
  • 35
5
votes
2 answers

SQL Database storing different types of values (in or simulated as a single field)

In a database I want to be able to assign values of a varying type to variables in a variable table. So do I need a separate value table for each value type? If so, I am not sure how you would actually link Values to the right table and thus right…
Matt
  • 351
  • 1
  • 5
  • 15
5
votes
1 answer

SQL Server 2008 - Multiple Cascading FK's - Do i need a trigger?

I have a 1..* relationship between User and Post. (one user has many posts) Post has a FK called "UserId", which maps to the "UserId" field on User table. I tried to set this FK as Cascade UPDATE/DELETE, but i get this error: 'Users' table saved…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
5
votes
2 answers

My Octobercms pivot table gets the data that model table should get when i try to add to it

I have an annoying problem, using latest OctoberCMS build (318), where it tries to save the wrong data to the pivot table instead of model table. I have a model Businesses, and a model Openinghours: Model for Businesses: `public $table =…
Terje Nesthus
  • 810
  • 3
  • 12
  • 30
5
votes
2 answers

Laravel 5.1 Delete relationships

My models relationship is oneToMany eg: PatientToSample Patient_Model: class Patient_Model extends Model implements Jsonable{ use SoftDeletes; protected $table = 'patients'; public function samples(){ return…
麦志坤
  • 117
  • 1
  • 9
5
votes
1 answer

Entity Framework (Code First) One to Many and One to One relations (with two entities). How to?

I'm trying to do this with EF Code First: There area two tables: Users and Areas. One User belongs to one required area and one Area can have zero or one User (as administrator). Then: Users *..1 Areas and Users 0..1 Areas The Users class: public…
5
votes
1 answer

Django generic relation field reports that all() is getting unexpected keyword argument when no args are passed

I have a model which can be attached to to other models. class Attachable(models.Model): content_type = models.ForeignKey(ContentType) object_pk = models.TextField() content_object = generic.GenericForeignKey(ct_field="content_type",…
Joshua
  • 547
  • 1
  • 5
  • 13
5
votes
2 answers

Rails: Belongs_to Polymorphic Association + conditions

So I have this model: class Model < ActiveRecord::Base attr_accessible :to_id, :to_type belongs_to :to, polymorphic: true end I was wondering if I could add another relationship when belongs_to is on a specific type: class Model <…
Augustin Riedinger
  • 20,909
  • 29
  • 133
  • 206
5
votes
1 answer

Two foreign keys on the same column from one table

i have a project table which has a image_id field and a newsimage_id field. Both are linked to the image table. But InnoDB doesn't allow me to set a foreign key for both fields to the same column (id). Is there a way I can do this or is it not…
makeflo
  • 53
  • 1
  • 3
5
votes
2 answers

Laravel Specifying a condition for a morphMany collection

I have the following Eloquent relationship class Broker extends Eloquent{ public function configurable(){ return $this->morphTo(); } } class ProductConfiguration extends Eloquent{ public function productConfigurations() { …
Kevin Bradshaw
  • 6,327
  • 13
  • 55
  • 78
5
votes
3 answers

Alternative to multi-valued fields in MS Access

Related question: Multivalued Fields a Good Idea? I know that multi-valued fields are similar to many-to-many relationship. What is the best way to replace multi-valued fields in an MS Access application? I have an application that has multi-valued…
Jay
  • 1,210
  • 9
  • 28
  • 48
4
votes
2 answers

Cross-Store weak relationship with Fetched Properties?

I would like to separate my reference data from my user data in my Core Data model to simplify future updates of my app (and because, I plan to store the database on the cloud and there is no need to store reference data on the cloud as this is part…
Clement M
  • 709
  • 6
  • 14
4
votes
1 answer

Codeigniter Datamapper Cross-Database Joins

Good morning, I am currently working on a project that utilises Codeigniter and the Datamapper Library (http://datamapper.wanwizard.eu). The project uses a central database for user data (called "base") and a seperate database for the application…
Daniel Greaves
  • 987
  • 5
  • 24
4
votes
3 answers

Core Data multiple relationships to same entity

I have a data model I'm trying to port from a SQLite based table structure to a Core Data model. My SQLite structure has a Zones table and a TransitLogs table. A TransitLog can have the following (in my sqlite…
earthtrip
  • 41
  • 2
4
votes
2 answers

Undefined offset: 1 error for laravel validation

I have some validation on my form in laravel to ensure the gift the user is claiming is one assigned to their campaign with the below code 'gift_id' => 'required|int|exists:gifts,campaign_id,' . \Auth::user()->campaign->id, But on form submission I…
user6073700
  • 230
  • 4
  • 17