associations

has_one update problem

I have two models, User and Account. Each user may have one account. Creating an account for a user works fine. My problem is that when I try to update the account, the previous accounts user_id is nullified and a new account row is created with the user_id. I do not want this happening. I want to update the existing row with the chang...

Ruby on Rails Associations

Hey all, I am starting to create my sites in Ruby on Rails these days instead of PHP. I have picked up the language easily but still not 100% confident with associations :) I have this situation: User Model has_and_belongs_to_many :roles Roles Model has_and_belongs_to_many :users Journal Model has_and_belongs_to_many :roles ...

Beginning with Datamapper, Association question

I'm just diving into Datamapper (and Sinatra) and have a question about associations. Below are some models I have. This is what I want to implemented. I'm having an issue with Workoutitems and Workout. Workout will be managed separately, but Workoutitems has a single workout associated with each row. Workout - just a list of types...

Rails find through association

class Customer < ActiveRecord::Base has_one :address, :foreign_key => "customerid" end class Address < ActiveRecord::Base belongs_to :customer, :foreign_key => "customerid" end How do I find records in customer that do not have customerid in address table? in SQL i'd do select * from customer a, address b where a.custome...

Hibernate associations

what are the minimum tables I need for many to many associations in Hibernate? ...

Passing two variables to separate table...associations problem

I have developed an application and I seem to be having some problems with my associations. I have the following: class User < ActiveRecord::Base acts_as_authentic has_many :questions, :dependent => :destroy has_many :sites , :dependent => :destroy end Questions class Question < ActiveRecord::Base has_many :sites, :dependent...

Size of assosiation in Hibernate criteria.

Hello guys. I've faced with a problem when querying with Hibernate Criteria in Grails. Take a look: def visitors = Client.withCriteria{ visits{ use ( TimeCategory ) {between('date',date,date+1.month-1)} } sizeGe("visits",params.from) sizeLe("visits",params.to) fetchMode("v...

Ruby on Rails and database associations

Hi to all, I'm new to the Ruby world, and there is something unclear to me in defining associations between models. The question is: where is the association saved? For example, if i create a Customer model by executing: generate model Customer name:string age:integer and then i create an Order model generate model Order descriptio...

Query a Hibernate many-to-many association

In Hibernate HQL, how would you query through a many-to-many association. If I have a Company with multiple ProductLines and other companies can offer these same product lines, I have a Company entity, a ProductLine entity and an association table CompanyProductLine. In SQL, I can get what I need like this: select * from company c wh...

Get KDE to run a bash script.

I have a bash script that takes a file name as an arg. It works great from the command line. When I right-click a file in KDE and select "open with", then point it to my script, it doesn't run. What am I doing wrong? ...

Ruby on Rails updating join table records

Hey, I have two models Users and Roles. I have setup a many to many relationship between the two models and I have a joint table called roles_users. I have a form on a page with a list of roles which the user checks a checkbox and it posts to the controller which then updates the roles_users table. At the moment in my update method I...

What is the importance of association multiplicity in class diagrams?

What is the importance of association multiplicity in class diagrams? Why and when should we indicate them? Thanks. ...

Passing user_id, site_id, and question_id to same table on create...

I can't seem to figure out how to do this. I am trying to pass four different variables to a single table. To be more specific I am trying to create a "like" in a likes table that also captures the site_id (like an answer), user_id, and the question_id. Here is the set up. class Like < ActiveRecord::Base belongs_to :site belongs_to ...

Implementing the tree with reference to the root for each leaf

Hi, i implementing a products catalog, that looks, like this: group 1 subgroup 1 subgroup 2 item 1 item 2 ... item n ... subgroup n group 2 subgroup 1 ... subgroup n group 3 ... group n The Models: class CatalogGroup < ActiveRecord::Base has_many: catalog_items has_many :catalog_item...

Why it's important to specify the complete class name in your association when using namespaces

In my Rails application there is a model that has some has_one associations (this is a fabricated example): class Person::Admin < ActiveRecord::Base has_one :person_monthly_revenue has_one :dude_monthly_niceness accepts_nested_attributes_for :person_monthly_revenue, :dude_monthly_niceness end class Person::MonthlyRevenue < Active...

Displaying count for current_user 'likes' on a 'question' in questions/show.html.erb view

I have an application that allows for users to create questions, create answers to questions, and 'like' answers of others. When a current_user lands on the /views/questions/show.html.erb page I am trying to display the total 'likes' for all answers on that question, for the current_user. In my Likes table I am collecting the question_...

Wrapping my head around MongoDB, mongomapper and joins...

I'm new to MongoDB and I've used RDBMS for years. Anyway, let's say I have the following collections: Realtors many :bookmarks key :name Houses key :address, String key :bathrooms, Integer Properties key :address, String key :landtype, String Bookmark key :notes I want a Realtor to be able to bookmark a House and/or a ...

Displaying pic for user through a question's answer

Ok, I am trying to display the profile pic of a user. The application I have set up allows users to create questions and answers (I am calling answers 'sites' in the code) the view in which I am trying to do so is in the /views/questions/show.html.erb file. It might also be of note that I am using the Paperclip gem. Here is the set up: ...

What's the use of has_one :through here (example from Rails guide)

Why they are using has_one:through here. We can do the same with has_one only. What's the need of making a new class. Can you give me any good example? Here is the link for the original example from Rails guide EDIT We can do the same thing in this way what's the use of making it a has_one:through class Supplier < ActiveRecord::...

Rails uses wrong class in belongs_to

I have an application managing software tests and a class called TestResult: class TestResult < ActiveRecord::Base belongs_to :test_case, :class_name => "TestCase" end I'm right now migrating from Rails 1.x to 2.3.5. In Rails 1.x everything works fine. When trying to access the association in Rails 2.3.5, I get the following err...