model-associations

How do rails association methods work?

How do rails association methods work? Lets consider this example class User < ActiveRecord::Base has_many :articles end class Article < ActiveRecord::Base belongs_to :user end Now I can do something like @user = User.find(:first) @user.articles This fetches me articles belonging to that user. So far so good. Now further I ...

Rails polymorphic associations, two assoc types in one class

Consider a class: class Link < ActiveRecord::Base has_many :link_votes, :as => :vote_subject, :class_name => 'Vote' has_many :spam_votes, :as => :vote_subject, :class_name => 'Vote' end The problem is, when I'm adding a new vote with @link.link_votes << Vote.new the vote_subject_type is 'Link', while I wish it could be 'link_vot...

CakePHP: shortcomings with indirectly associated models

I'm having some issues with dealing with indirectly associated models in cakephp. My current model setup is as follows: Deliveries hasOne License License belongsTo Delivery License hasAndBelongsToMany Product (and vice-versa) License hasAndBelongsToMany ProductOption (and vice-versa) I'm trying to save information about ALL of these ...

How to access ':has_many :though' join table data when using to_json?

Hi folks, I have three models (simplified here): class Child < ActiveRecord::Base has_many :childviews, :dependent => :nullify has_many :observations, :through => :childviews end class Childview < ActiveRecord::Base belongs_to :observation belongs_to :child end class Observation < ActiveRecord::Base has_many :chi...

Filter data from intermediate table with AND link

Hello community, i'have following scenario: Tables and Columns (Database Type: Microsoft Sql Server 2005): Table: Entries EntryID ... other unimportant columns Table: Attributes AttributeID Table: EntryAttributes EntryID [Releation To: Entries->EntryID] AttributeID [Releation To: Attributes->AttributeID] So, how can i sele...

Rails: setting up has_many_through association between tables from different databases

I am trying to setup a has_many :through relationship between two models User and CustomerAccount through another join model AccountOwnership (users and account_ownerships tables are in one db, say db1 and the customer_accounts table is in remote db, say db2). Here is the relevant code, that sets up the associations class User < Activ...