similar to: Multiple Relations between 2 tables

Displaying 20 results from an estimated 10000 matches similar to: "Multiple Relations between 2 tables"

2006 Jan 05
13
Naming convention for foreign keys
Hi, In "Agilge Web Development With Rails" on page 217, an example of foreign keys is shown. I am however unable to find a definition of wheater the naming of the index is significant. On the above mentioned page, this line is shown in the example: constraint fk_items_product foreign key (product_id) references products(id) In "fk_items_product", "items" is
2008 Sep 12
1
Referencing exactly two models of the same kind
Hi, how do I solve this in Rails: Lets say I have a User and a Message. Now, a Message is sent from one User to another User, which means that in the Message I have to reference a User twice! This seems to be a problem, if I do not user one-to-many or many-to- many relationships, because it seems to me as if I could reference a Model of the same type only once. However, I would like the Message
2006 Mar 23
4
belongs_to more than one model
Suppose I have one table: states id statename And I have two other tables that contains states: houses id color state_id places id place_name state_id How would my model relationships look like? class State < ActiveRecord::Base belongs_to house belongs_to place end class House < ActiveRecord::Base has_one state end class Place <
2006 Aug 16
11
just don''t ''get'' "has one" and "belongs to one"
Well, I understand what they do and how, I just don''t get why! It seems to me that any time you would have this relationship between two tables...they should be one table! Agile Rails book gives what seems to me to be a lame example for this. They use the example of an "invoice" and an "order". An invoice belongs to an order and an order has one invoice. Seems
2007 Oct 18
4
Polymorphic Association?
Hi there- I''m a newbie to this board, RoR, and web development in general. So please forgive me if this is in the wrong place or if the solution is really simple... I''m trying to conceptualize the relationships between a series of models for a page creation function. What I''d like is to have a Content Page which consists of a series of Content Blocks. The Content
2006 Jun 03
8
confused about ActiveRecord relationships
I am very confused about where to put the belongs_to and the has_one (and other relationship identifiers). I have read the RDoc and the agile book many times about this and I think i still see it backwards. Let me outline my app so you have an understanding... I have 2 tables: Schools { id, school_name, address_id } and Addresses { street1, street2, city, state, zip, country } *** this
2006 Mar 08
2
Displaying related tables in forms.. probably an easy question!
Hey All, I have two tables.. One belongs to another. Why can''t I reference table1.table2.attribute? Specifically, using scaffolding: property.rb - has_one :PropertyType property_type.rb - has_many :Properties property_controller - def list @property_pages, @properties = paginate :properties, :per_page => 10 end list.html: 1. <% for property in @properties %> 2.
2006 Mar 23
3
when (not) to use belongs_to
I know you get a lot of questions like this, but I couldn''t find one which answers exactly what I''m after. I''m reasonably new to rails, and I''m having a bit of trouble with when to use belongs_to. On the rails wiki ( http://wiki.rubyonrails.org/rails/pages/belongs_to), it says "In general, the Foo model belongs_to :bar if the foo table has a bar_id foreign
2013 Feb 25
3
ActiveRecord associations: design question
Hi guys, In my Rails app, I have three models: A, B and C, with the following relationships: - B hasMany C - C belongsTo B I would like A to "has_one" instance of B+C. By that I mean A needs to be linked to a specific instance of B AND a specific instance of C. My first guess would be to create a fourth object, say B_plus_C that would: - belongs to B - belongs to C - belongs to A Is
2007 Aug 21
4
[AWDwR] Confused about has_one and has_many
Heya everyone! I am quite new to Rails and I am reading AWDwR. I am at Task E "Check Out!". I understand it quite well, but I have a problem with the last playground exercise: Add a Table which contains the payment types. All goes well, but I am not sure whether I should use has_many or has_one(as in the Playground wiki at http://wiki.pragprog.com/cgi-bin/wiki.cgi/PT-E-3). I use the
2006 May 01
2
Getting my schema straightened out
I''m trying to map Rails to an existing schema, and having a bit of a time of it. I''ve got a table Content, and I''ve got a table Review, which is a type of content. So content has an ''id'' field, and Review has a ''contentid'' field. Not all Content has a Review, but all Reviews have exactly one Content. How do I represent this?
2006 Jun 06
1
Please Help with single table inheritance relationships
I''ve been searching the web, wikis, and more, and I haven''t turned up examples of how to have multiple entities in a single-table inheritance related to anything. I have an addresses table, but multiple entities can have Addresses: both Person (which has 2 addresses) and Retailer. I''ve been told that I need to use single-table inheritance, and this was my attempt:
2007 Nov 14
1
New Foxy Fixtures (Rails 2) & STI (Single Table Inheritance)
I''ve got some problems right now using the new model for relationships in fixtures (by label, not by id) and STI. What I''ve got, is a couple of models: Attachment --> FileDownload Version Version has_one file_download with file_download_id on the versions table In my fixtures, I have two FileDownloads in my attachments.yml like so: hemingway_alpha_zip: size: 100
2006 Apr 02
7
RANT: belongs_to -> refers_to
Every once in a while, I pipe up and whine that "belongs_to" should really be ''refers_to" [http://dev.rubyonrails.org/ticket/2130]. It''s time again. I''ve got a bunch of stuff going onto eBay, so, like any good engineer, I don''t just post it manually: I design a Rails-based inventory database that creates a semantically-correct XHTML/CSS auction
2006 Apr 21
2
me.defeated!
Good afternoon (as appropriate ; ) I''m having a problem and thought I''d run it past these forums to see if there even was a reasonable solution to it. I''m trying to set up a rails application to pull data from a legacy database. The trick is, that the database really wasn''t created with RoR convention over configuration in mind. The trick is that every
2011 Jul 20
2
polymorphic assoc seems only best for multiple parents ?
I have done a little polymorphic associations stuff and have refreshed my memory on it again. What it seems like is that if I have a particular record and I want to make it easy for many different parent records to associate with it using has_one or has_many, that is fine. If I want a parent record to have multiple kinds of children through one association, I don''t see how to do that
2006 Mar 19
2
Multiple polymorphic belongs_to declarations
I have the following models: class Card < ActiveRecord::Base belongs_to :deck belongs_to :front, :polymorphic => true belongs_to :back, :polymorphic => true end class TextContent < ActiveRecord::Base has_one :card, :as => :front has_one :card, :as => :back end The conflicting has_one declarations don''t work. What I need is
2006 Jul 23
8
destroy vs delete
what is the difference between destroy and delete in AR I am not sure what they mean by "Destroys the record with the given id by instantiating the object and calling destroy<http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866>(all the callbacks are the triggered). If an array of ids is provided, all of them are destroyed." in
2006 May 12
1
can I fake has_one :through?
I''m having a difficult time wrapping my head around a set of models and their associations and seeing how they map into Rails. I''ll try to lay out my problem using the has_many and belongs_to structures. I have a RuleSpace, a Rule, and a Subject. A RuleSpace has_many Rules A RulesSpace has_many Subjects through Rules A Rule belongs_to (many) RuleSpaces A Rule has_many
2006 Apr 10
6
Single Table Mapping
This is pretty simple, but I must be missing the obvious. I''ve got a table that''s similar to this: USERS: - id int - username varchar(64) - password varchar(64) - role_id int ROLES: - id int - description varchar(16) I''ve had no troubles doing has_many relationships at all. But I want to map the user.role directly to the role model automatically (which sounds