associations

Rails migration: t.references with alternative name?

So I have a create_table like this for Courses at a School: create_table :courses do |t| t.string :name t.references :course t.timestamps end but I want it to reference TWO other courses like: has_many :transferrable_as #a Course has_many :same_as #another Course can I say t.references :transferrable_as, :as=> :c...

Unidirectional One-to-Many Associations in Entity Framework 4?

Does EF 4 support unidirectional one-to-many associations, as in: public class Parent { public int Id { get; set; } public string Something { get; set; } public List<Child> AllMyChildren { get; set; } } public class Child { public int Id { get; set; } public string Anotherthing { get; set; } // I don't want a back-reference...

Rails association query

I am having trouble accessing the correct information in my rails model (which I believe to be correct) The schema for my tables are create_table :schools do |t| t.string :name t.timestamps end create_table :variables do |t| t.string :name t.string :category t.timestamps end create_table :data do |t| t.string...

Which type of Rails model association should I use in this situation?

I have two models/tables in my Rails application: discussions and comments. Each discussion has_many comments, and each comment belongs_to a discussion. My discussions table also includes a first_comment_id column and last_comment_id column for convenience and speed. I want to be able to call discussion.last_comment for the last comment ...

Associated models in Rails?

Hi Everyone, In my rails application I have two models called Kases and Notes. They work in the same way comments do with blog posts, I.e. each Kase entry can have multiple notes attached to it. I have got everything working, but for some reason I cannot get the destroy link to work for the Notes. I think I am overlooking something tha...

Question About Fk refrence in The Collection

Hi , i have 2 entities : ( person ) & (Address) with follwing mapping : <class name="Adress" table="Adress" lazy="false"> <id name="Id" column="Id"> <generator class="native" /> </id> <many-to-one name="Person" class="Person"> <column name="PersonId" /> </many-to-one> </class> <class name="Person" table="Pe...

Find the associated program to open a file using Java

I wish to open a file (lets say, a word document) from a Java application using the associated program installed on the computer (in this example, using MS Word or Open Office Writer). The catch is that I want to wait until this subprocess finishes, which can be done using the waitFor() method in the Process class. String executable = ...

Rails app perfomance or how to cache method result.

I have two models: Program < ActiveRecord::Base has_many :events def federal_financing events.sum(&:federal_financing) end def regional_financing events.sum(&:regional_financing) end def local_financing events.sum(&:local_financing) end end Event < ActiveRecord::Base belongs_to :program # events table h...

Find items with belongs_to associations in Rails?

Hi Everyone, I have a model called Kase each "Case" is assigned to a contact person via the following code: class Kase < ActiveRecord::Base validates_presence_of :jobno has_many :notes, :order => "created_at DESC" belongs_to :company # foreign key: company_id belongs_to :person # foreign key in join table belongs_to :survey...

Challenges with Associating files

In my project properties I go to publish, options, and file associations and enter ".cms", "Contact manager File" "pqcms" and "1icon.ico", but when I publish and install it does not appear to associate the files...I want to be able to double click on the file and have it open the program but it does not appear to do so. I believe there ...

has_many, belongs_to association where has_many associated model has two alias fk in belongs_to associated_model...

I have a User model that has many fights. Fight belongs to User. There are two foreign keys in the fight table that reference back to the user PK -- challenger_id and challengee_id. The trick is how do I write the has_many association on the User model so that it returns fights where user_id = challenger_id or challengee_id? ...

cakephp paginate model with multiple association

I have three tables : Units, Offers and Agents with following associations Unit hasMany Offers Offer belongsTo Agent When I paginate Unit table I get all the units and all the corresponding Offers for each unit , but not the Agent that offer belongs to. Ex:  Unit1   offer1   offer2  Unit2   offer1   offer2   offer3 ... And I want t...

Complex Rails associations question...

I have three models of concern here: User Fight FightPunches Punches The associations are as follows: User has many fights, foreign_key => 'challenger_id or challengee_id' Fight belongs to challenger, as User Fight belongs to challengee, as User Fight has many fight_punches FightPunches belongs to fight Fight has many punches, thro...

What's best here, Rails Association Scopes or Just SQL?

I'm not quite sure what to do here, here's the situation: Given these models... class Post < ActiveRecord::Base has_many :post_assets has_many :assets, :through => :post_assets acts_as_scopeable :assets, :scopes => [:featured] end class PostAssets < ActiveRecord::Base belongs_to :post belongs_to :asset # context is so we...

Rails has_many :through and Setting Property on Join model

Similar to this question, how do I set a property on the join model just before save in this context? class Post < ActiveRecord::Base has_many :post_assets has_many :assets, :through => :post_assets has_many :featured_images, :through => :post_assets, :class_name => "Asset", :source => :asset, :conditions => ['post_assets.context ...

Passing association parameters on ActiveRecord object creation

In my application I have 2 classes like this: class City < ActiveRecord::Base has_many :events end class Event < ActiveRecord::Base belongs_to :city attr_accessible :title, :city_id end If I create city object: city = City.create!(:name => 'My city') and then pass parameters to create event like this: event = Event.create!...

Problem with nested associations in Rails3

Hi guys, I'm having a problem with some associations in Rails3. I have the following associations InformationCategory :has_many => Informations :has_many => InformationValues I'm able to succesfully do the following: Information.first.information_values => [#InformationValue..] I'm also able to do the following: InformationCateg...

Cakephp, ordering associated tables.

Hi, When I search a model which "has many" of something else. For example a blog post has many categories. When searching for blog post with categories associated, how do I order the associated categories? When the array is returned it ignores the order on the category model and defaults to it's usual id order. Cheers. ...

Foreign key (class_id) not populating in belongs_to association

Hello, I'm new to rails and building a small test app on rails3 (beta4). I am using Authlogic to manage user sessions (setup in a standard fashion as per this tutorial) I have scaffolded and setup a card model (a post basically), and set up the basic active record associations for a belongs_to and has_many relationship user.rb has_m...

In OOP, should dependencies hold a reference to their parent?

I have an Order object to represent a Prospective Order/Receipt. This is an entity. It has an identity. I have a Writer object to read the Order object's properties and display it nicely. It is a bit of a chore to have individual getters for all the pieces of the Client's Billing Details. So, I am thinking of letting the Writer object...