associations

(Rails) Various associations between otherwise unrelated entities?

Hi All, Ok, I've got a bit of an odd situation (as if none of my others were...). Basically I have a setup where there are 4 entities: Sites -> Buildings -> Meters -> Values I then have a fifth entity (Charts) that creates reports on the Values. I have a request to allow for Charts to be visually associated with any of those items ...

rails renaming associations

I have two models, TreeNode and User. Each user has_one TreeNode, which is the root of the tree. class TreeNode acts_as_tree belongs_to :user end class User has_one :tree_node end I would like to have this setup so that rails will make the association so that I can do something like User.first.tree instead of User.first.t...

How to specify join conditions in Rails for belongs_to assocation?

Hi there, I'm trying to create an association between two models using join conditions rather than a foreign key. Does anyone know if this is possible? For example I want to join products to pricing points. A product has a price and a pricing point has a minimum and maximum amount and a name. Eg. Min = 0, Max = 20, Name = Less than $20...

Open Source Data Mining Software

Hey everyone! I was wondering; what is the best open source software that I can use for non-binary association rule generations. I need a non-binary implementation because converting my currently non-binary data to binary data would not give the desired results. Thanks and can't wait to here your comments! ...

association mining in WEKA

Hey Everyone, I am trying to generate a set of association rules out of a set of data using WEKA. I have converted my .csv file to an .arff file that is usable by WEKA. Once in the software I remove all string fields form the data set and convert everything to nominal data. My problem is when I go to the association rules and try to ge...

How best to "merge" two objects and their associations in rails?

Here's my situation: I have 2 person objects, person1 and person2, which were created from two different external data sources. I have a manual process that I use that has determined that person1 and person2 actually refer to the same person, so what I want to do is "merge" them into a single person, and remove the duplicate. I have ...

Double join with habtm in ActiveRecord

I have a weird situation involving the need of a double inner join. I have tried the query I need, I just don't know how to make rails do it. The Data Account (has_many :sites) Site (habtm :users, belongs_to :account) User (habtm :sites) Ignore that they are habtm or whatever, I can make them habtm or has_many :through. I want to b...

How to normalize an association between weekly participations and weekly questions?

I am implementing a contest system in which the user has to choose the correct answer of multiple questions. Each week, there is a new set of questions. I am trying to find the correct way to store the user participations in a database. Right now I have the following data model: Participation Week +--------------+ ...

has_one relationship validation in rails

Since has_one doesn't provide a before_add callback to allow validation, how do I prevent rails from destroying the old association even when the new one does'nt pass validation? susan :has_one :shirt shirt :belongs_to :susan susan.shirt = a_nice_shirt this destroys whatever association was present beforehand, even if the new shirt is...

How do I setup model associations in an RSpec test?

I've pastied the specs I've written for the posts/show.html.erb view in an application I'm writing as a means to learn RSpec. I am still learning about mocks and stubbing. This question is specific to the "should list all related comments" spec. What I want is to test that the show view displays a post's comments. But what I'm not ...

how to delay the creation of the association until the subclass is created in active record?

I have four tables: jp_properties, cn_properties, jp_dictionaries and cn_dictioanries. And every jp_property belongs to a jp_dictionary with foreign key "dictionary_id" in table. Similarly, every cn_property belongs to a cn_dictionary with foreign key "dictionary_id" in table too. Since there are a lot of same functions in both proper...

How to test association extension logic in rails with minimal DB overhead.

I am a fan of using mocks and stubs everywhere I can to keep my specs running quickly. I'm kind of stumped as to how I might do this to test the find_special method in the following: has_many :foos do def find_special if proxy_owner.baz ... find stuff else ... find other stuff end end end ...

Retrieve from multiple relations, ruby on rails

Hello, user (has_many :user, has_many :comments) post (belongs_to :user, has_many :comments) comment (belongs_to :user, belongs_to :post) Now I am trying to retrieve all posts (having atleast one comment of the user) updated with comments from last comment of user in that post (i will be using user's updated_at attribute for this) Exa...

iPhone file extension app association

Hello everybody! On my iPhone, I'm running an app called Caissa Chess. After registering the app with the manufacturer (this is optional) I received an email, containing a chess puzzle. The crucial part of the mail message, showing a chess diagram looks like this: <a href="chess://puzzle/8/p1R3p1/4p1kn/3p3N/3Pr2P/6P1/PP3K2/8 w ?term=w2...

rails validating multiple child models in a complex form

Hi, I am using multiple child models in a complex form (a la http://railsforum.com/viewtopic.php?id=28447). The form works great, but I need to validate a property of the set of child models before accepting the form data into the database. I've come up with one mostly-working, very-kludgy way of doing this. Seems like there has to be a...

Remove assosiation instead of destroying object when :allow_destroy => true

When using the new accepts_nested_attributes_for in ActiveRecord, it's possible to use the option :allow_destroy => true. When this option is set, any hash containing nested attributes like {"_delete"=>"1", "id"=>"..."} passed to update_attributes will delete the nested object. Simple setup: class Forum < ActiveRecord::Base has_many ...

How do I update a model object's associated object?

Hi, I want to something like the following: @user.update_attributes(:name => "Obama", :profile => { :current_location => 'US' }) where User has_one profile. ...

Hibernate unidirectional one to many association - why is a join table better?

In this document (scroll down to the Unidirectional section): http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections it says that a unidirectional one-to-many association with a join table is much preferred to just using a foreign key column in the owned entity. My question i...

Rails, ActiveRecord: how do I get the results of an association plus some condition?

hi, I have two models, user and group. I also have a joining table groups_users. I have an association in the group model: has_many :groups_users has_many :users, :through=> :groups_users I would like to add pending_users which would be the same as the users association but contain some conditions. I wish to set it up as an associatio...

Getting fields_for and accepts_nested_attributes_for to work with a belongs_to relationship

I cannot seem to get a nested form to generate in a rails view for a belongs_to relationship using the new accepts_nested_attributes_for facility of Rails 2.3. I did check out many of the resources available and it looks like my code should be working, but fields_for explodes on me, and I suspect that it has something to do with how I ha...