data-modeling

Relational database design question - Surrogate-key or Natural-key?

Which one is the best practice and Why? a) Type Table, Surrogate/Artificial Key Foreign key is from user.type to type.id: b) Type Table, Natural Key Foreign key is from user.type to type.typeName: ...

Many-to-many link table design : two foreign keys only or an additional primary key?

Hello experts, this is undoubtedly a newbie question, but I haven't been able to find a satisfactory answer. When creating a link table for many-to-many relationships, is it better to create a unique id or only use two foreign keys of the respective tables (compound key?). Looking at different diagrams of the Northwind database for exam...

CakePHP - Custom hasOne Object Association - Using a Join Table instead of in-table foreign keys?

In CakePHP, I'm trying to build a $hasOne relationship, but I can't add a foreign key to the tables (for legacy reasons). Is there any way I can create a join table (object1_object2) and link them together like this? I want to leverage Cake's powerful object relationship functionality, so if there's a way I can make this custom associa...

has_many :through association results in NameError

I'm trying to do a many-to-many relationship in rails. It's my first try but I'm having a hard time to succeed. I want to be able to do @user.properties or @property.users. #property.rb has_many :ownages, :dependent => :destroy has_many :users, :through => :ownages #user.rb has_many :ownages, :dependent => :destroy has_many :properties...

SQL Architecture: Is this a justified case to have only one table storing multiple entity types? (using a self JOIN)

I rarely come across a situation where a single table for multiple entity types seems better than one table per entity type. Here's an example that makes sense to me, but academically it seems wrong. QUESTION: Can I do this and still have a "sound" architecture? Example Follows Suppose two entity types, a corporation and a person. A c...

Mysql table structure and designing

I have two tables both i am working like below concept... When any record will be inserted 'id' of first table ('id' is unique and auto_increment), I want to use this id value for further insertion in my second table (that means id will be foreign key).How should I should to design my table? If i am inserting values and further fetch...

How should I model a group relation in the database and in OOP?

I have instances of Item that I would like to have in groups ItemGroup. But if an Item is moved to another itemgroup, I would like to keep track of the change for accountability reasons. E.g. I need to know if an Item was in one ItemGroup in October and another in September. How should I model this in the database? How should I model th...

Logical Model versus Domain Model

I am not a database guy. My understanding of data modelling is not extensive. From that limited understanding the logical data model is an abstraction of the physical data model, not containing anything specific to the specific storage product/medium. The logical data modelling does appear to involve business subject matter experts in th...

Data modeling question

My clients use one of the following when they sign up for my application: Foo API (requires a "auth_key", "password", "email") Acme API (requires a "secure_code", "username", "password") Bar API (requires a "xyz_code", "pass_key") (fake names, and about 15 more omitted for simplicity) I would prefer not to have 10-15 tables in my da...

What's the best way to design an Entity / Relationship Model?

For example if I have 20 tables, I have to design it by section? i.e CLIENT (id, name...) -- orders -- ODERS_DETAIL(id, products...) . . . lives --- ADDRESS(...) Or I can use The MySQL Workbench EER Model (To me, it looks like the Pysical Model)? Or like this: Data Modeling Levels ...

Inheritance in Enterprise Architect

I have a class within a package. And I have another class in another package. I would like to link this second class to first. Since the first is a legacy of the second. I'm not able to make this relationship. We tried, but in neither case are the methods of the second brought the first. Any help is welcome. Thanks Class A Class B ...

Database design: bigger table vs query the entity for every row in dataTable

I have a table of NewsFeed. NewsFeed + id + fromUserId + targetId + type so the news is like this: Tom Wakefield commented on Peter Smith's profile. So either I add two more fields into my NewsFeed call fromUserName and targetUserName OR For every row I display in my dataTable I would query from the Entity. <p:dataTable value="#{my...

Generally, are string (or varchar) fields used as join fields?

We have two tables. The first contains a name (varchar) field. The second contains a field that references the name field from the first table. This foreign key in the second table will be repeated for every row associated with that name. Is it generally discouraged to use a varchar/string field as a join between two tables? When is t...

Rails 3 has_one/has_many question

I am writing an application that contains a database with several tables and joining tables and so forth... the two I am working with currently (and am stumped on) are my pages table and my templates table. Now a page can contain only one template, but a template can have many pages. Model for Page: class Page < ActiveRecord::Base h...

What's the best way to structure these relationships? To HABTM or not?

Just looking for some advice on how to structure my relationships in an app that I'm making. I have the following models: activity # golf, karaoke event # golf competition followed by all-night karaoke boat party post # write-up of the golf and karaoke event mentioned above gallery # photos from the golf and karaoke event Que...

Magento: which catalog_product_flat I need to select from? and what is catalog_product_entity_datetime table?

Hi everyone, To know who are the customers needed to be sent the notification mail and know which are the products remain 2 hours before the deal expired, I need to select from wishlist, wishlist_item, customer_entity and catalog_product_enity table which need to join with catelog_product_flat_X But there are many catelog_product_fla...

Django: Model Inheritance: FK & M2M

I dam trying to do this: http://docs.djangoproject.com/en/dev/topics/db/models/#be-careful-with-related-name Using this style This is saved as common/abstract.py class OtherModel(models.Model): something = Charfield(max_length=100) class Meta: abstract = True class Base(models.Model): fk_model = models.Fo...

Storing or computing totals for complex models

All, I'm developing an application using Zend Framework to manage tenders for construction work. The tender will be a rather complex set of models with an architecture resembling the code snippet below. My question is... should I store the total value of the tender as part of the tender model, or should I compute it each time it is re...

What's an Exclusivity Arc called in UML

Here's an example of what an Exclusivity Arc is (the green arc); what it's saying is that a Plane can have either Propellers or Jet Engines - but not both. In Barker ER notation, an exclusion constraint over two or more roles is shown as an “exclusive arc” connected to the roles with a small dot or circle. see http://www.o...

Enforcing Referential Integrity with Triggers Instead of Foreign Keys

I'm building a new database for a web-based application and find that I am frequently having to decide between flexibility of the model and meaningful foreign keys to enforce referential integrity. There are a couple of aspects of the design that lead me towards writing triggers to do what FKs would normally do: Parts of the model use...