associations

How to Show Aggregation in terms of A Programming Code ?

Hi, I know about Association and Aggregation and Composition and Generalization what they are by definition. inheritance is "is a" relationship and composition is "has a" relationship. Class A { } Class B extends A { // this is Generalization } Class C { A ob; // this is composition } now my question is how the Aggregation and si...

Validating nested models?

To be more specific, "How do I validate that a model requires at least x valid associated models to be created?". I've been trying to validate nested models that get created in the same form as the parent (and ultimately show immediate validations a la jQuery). As a popular example, lets assume the following models and schema. class Pro...

If I have multiple types of an object, when should object.type be a string and when should it be a foreign key?

Let's say I have books which can be romance, fiction, or mystery. I have 2 realistic options to store this data. One is to have a type column in my books table that is a string with the value "romance", "fiction", or "mystery". The other is to create a book_types table and store the types in there. Then my books would have a type_id ...

Inheritance of LINQ to SQL data context

If I inherit one DBML file from another DBML file, is it possible to visually create associations to the data classes from inherited DBML? ...

Select from a table where associated table fieldname = 'x' in Cake PHP

In CakePHP, I have two tables, Countries & Networks. They have a HABTM relationship and are joined by countries_networks. I'm trying to get all countries from the countries table where the 'name' field in Networks = 'o2' I've realised I can't do this using a basic find(), so I've been experimenting with the containable behaviour. I hav...

Displaying associated objects

I am a ruby on rails newbie and had a question about the view logic in case of associated objects. My models look similar to class Post < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :post end And what I want to display is something like a list of all the posts and the 1st 3 comments f...

clarification of association terms

Hi Can anyone help me with a clarification of these terms; Relation, Association, linkage..etc. I have started a smaller study of UML with a particular focus on associations and their translation to source code. I have noticed various terms are used when describing associations. Can one of you that have more knowledge about this ar...

How to access and submit related polymorphic models in the same form, in Rails?

Suppose I have 3 models, Car, Motorcycle and Truck, and for each I have to enter a bunch of stuff, such as a list of known previous owners, traffic tickets, license plates, etc. So I created a model for each (PreviousOwners, PreviousPlates, etc) and set up polymorphic associations for the related models. The problem is, how can I enter ...

LinqToSql and Views don't have foriegn keys/associations?

Hi folks, I've got some tables in my Linq2Sql designer (in Visual Studio 2008). Works great. Now, I just tried dropping in a View onto the designer. It dropped on there ok, but there's NO foreign keys/associations. hmm. Ok, so then I tried to manually add an association between the View and a parent table. That worked .. but when i ...

select many through many... kind of

Hi all! This is my first post on Stack, so please bear with me if I breach any protocol. I'm working on a project in Rails (2.1.2), and I have a relations scenario that looks like this: event [has_many] days People (in different categories) can sign up for event days, giving the following binding results: category [has_many] custom...

How should I design classes for Many-to-Many relationships?

Suppose I am developing a software for a pharmaceutical company where each 'ProductionLine' has multiple 'Stages' and each Stage has multiple 'Machines' Now suppose I am maintaining three tables to record Stages and its Machines (leave the ProductionLine away for the shake of the discussion). (1) Stage (Basic data which represents all ...

Associate Extensions in Windows CE

How can I associate an extension of a file to an program in Windows CE? It's so boring to run my Python programs using cmd. If I associate Python with my *.py files I'm going to run my program faster. Thanks! ...

named_scope in rails with a has_many association

Hi all, I am trying to achieve what I think will be a fairly complex query using the magic of Rails without having lots of ugly looking SQL in the code. Since my database is dealing with rather specialised biomedical models I'll translate the following to a more real world scenario. I have a model Book that has_many :chapters and C...

(Rails, Associations) How do I remove a single HABTM associated item?

Ok, stupid question. How do you remove a HABTM associated item without deleting the item itself? For instance, say I have 3 STUDENTS that are in SCIENCE class together. How do I remove the SCIENCE object from the STUDENTS_CLASSES table without deleting the actual SCIENCE reference? I'm guessing that Student.Classes.first.delete is...

Removing one of the many duplicate entries in a habtm relationship?

For the purposes of the discussion I cooked up a test with two tables: :stones and :bowls (both created with just timestamps - trivial) create_table :bowls_stones, :id => false do |t| t.integer :bowl_id, :null => false t.integer :stone_id, :null => false end The models are pretty self-explanatory, and basic, but here they are: ...

Can a custom to_s method be created for a specific association collection?

I have an Entry model which has_many :tags. I want to be able to list my tags in an text input (ie. "tag-1, tag-2", etc.), however, I am running into an issue. If I just use form_for(:entry, form_options) do |f| f.text_field :tags end My text box gets created, but is filled with something like #<Tag:0xb79fb584>#<Tag:0xb79faddc>, w...

Removing an association from an entity

Hi, I have 2 entities: User and Company, with a FK from the User to the Company. I'm trying to remove the association and leave the user entity with a scalar property "CompanyId", but still have the "Company" entity in the model (mainly to increase performance, I don't need to full entity attached to it). I'm able to achieve that only ...

UML Notation - Aggregations/Compositions vs "Vanilla" Associations

I've recently spent a good deal of time performing detailed UML designs of various SW components that I have since written. Looking back on what I have recently finished and comparing that to when I first learned UML, I see that I now almost strictly use Aggregation and Composition relationships, and have virtually abandoned "vanilla" no...

Newbie question attribute from associated table not showing up in index view

Hi I know this is something simple I am doing wrong. I have three tables, installation, neighborhood, schools Installation: has_many :schools has_many :neighborhoods Neighborhood: has_many :installations has_many :schools Schools: belongs_to :installations belongs_to :neighborhoods I can't figure out how to show the name...

Does an association imply a dependency in UML?

In discussion about my answer to this question, there was some disagreement over how to model this code: public class MainClass { private Something something; public void Action() { OtherClass other = something.GetOtherClass(); } } The key points being: the Something class is an attribute in MainClass, sugge...