associations

Trouble with Hibernate One Way Associations

I'm trying to implement a Hibernate persistence layer in a Java application and I'm having some trouble with it. I'm encountering a no proxy error every time I attempt to access a simple, one way association. I haven't implemented Hibernate in quite the right way - I am using the thread method of Session control, which they do suggest ...

Rails Model Associations for Item-Item Relationship?

Looking for some guidance on the best way to implement this scenario: I have an items table (of products) and want to support the ability to cross-sell / up-sell / complement items. So there is an item-to-item(s) relationship here. In this join table I need to include additional attributes beyond the keys such as the sales_relation betw...

Rails: Factories and Associations in Functional Tests

I'm trying to figure out why this doesn't work. Let's say you three models, User, Foo and Bar. In order for a bar to be created the user must first create and validate a foo object. Class User #snip! has_many :foos has_many :bars Class Foo #snip! belongs_to :user has_many :bars Class Bar #snip! belongs_to :user belongs_to :foo I'm ...

How to avoid updating update_at flag while updating associated model in active record?

My association to models as follows People model belongs_to :category has_one :account, :through => :category category model belongs_to :account has_many :bookings account model has_many :categories Level model accepts_nested_attributes :peoples I wrote @level.update_attributes(params[:level]) in Le...

ActiveScaffold complains about association

I'm using ActiveScaffold to create an Admin UI. I have two models: Post and Comments. A Post has-many Comments, and a Comment belongs-to a post. There's a validates_presences_of :text validation the Comment model. The problem is that when I create a new Post from the Admin UI without creating a new Comment in the subform, ActiveScaff...

CakePHP HABTM relations listing

I'm have quite a problem while trying to make a list (for the admin section) of HABTM relations. Here's the deal: permissions: id, name; users: id, username; permissions_users: permission_id, user_id Permission HasAndBelongsToMany User I want to make a listing like such: User.id | User.username | Permission.id | Permission.name 1 | J...

Creating associated models on create in Rails?

I have to be dead tired because I really can't figure out such simple task as this. Having: class Account < ActiveRecord::Base has_one :subscription, :dependent => :destroy after_save :append_subscription private def append_subscription # TODO end end # Subscription(id: integer, account_id: integer, level: integer (: ...

MongoDB Many-to-Many Association

How would you do a many-to-many association with MongoDB? For example; let's say you have a Users table and a Roles table. Users have many roles, and roles have many users. In SQL land you would create a UserRoles table. Users: Id Name Roles: Id Name UserRoles: UserId RoleId How is same sort of relationship ...

Linq to SQL Associations with fixed fields

Linq to SQL, in the dbml designer (or otherwise) I have 3 tables: Orders, Deliveries and EmailTemplates. Orders have many Deliveries, and Orders and Deliveries have a status (int) field. EmailTemplates have a status they apply to and a bool IsForDeliveries field. I have Linq to sql associations for Order->EmailTemplate on order.st...

Rails belongs_to testing

I have a Proposal model that belongs to Project: class Proposal < ActiveRecord::Base belongs_to :project has_many :articles, :as => :document, :dependent => :destroy has_many :sections, :through => :articles # proposal has project - test/unit/proposal_test.rb validates_presence_of :project_id end The route I set up to show ...

Rails Photos, Users, Comments

Hi, It's driving me crazy. I have 3 models. User, Photo, Comments. Here is what I want to do. A user has many photos and comments A photo belongs to a user and has many comments And a comment belongs to user and to a photo So my models have these associations: User has_many :photos, :dependent => :destroy has_many :comments, :de...

Can you explain what's association relation in database?

I thought it was alias for simple foreign key relation,but seems not. Can you take MySQL as an example what is association relation? I guess it means many2many relation,is that true? ...

Ruby-on-Rails: Multiple has_many :through possible?

Is it possible to have multiple has_many :through relationships that pass through each other in Rails? I received the suggestion to do so as a solution for another question I posted, but have been unable to get it to work. Friends are a cyclic association through a join table. The goal is to create a has_many :through for friends_comm...

How to create Rails models with multiple complex associations/joins?

I am trying to figure out how to create ActiveRecord models with associations that can yield the same results as this SQL query: SELECT login, first_name, last_name, email_address FROM accounts INNER JOIN people ON person.id = accounts.person_id INNER JOIN email_address_people ON person.id = email_address_people.person_id INNER JOIN ...

Can't grab foreign key during after_create callback because it doesn't exist yet!

I have some models all linked together in memory (parent:child:child:child) and saved at the same time by saving the top-most parent. This works fine. I'd like to tap into the after_create callback of one of the children to populate a changelog table. One of the attributes I need to copy/push into the changelog table is the child's f...

Modeling Buyers & Sellers in a Rails Ecommerce App

I'm building a Rails app that has Etsy.com style functionality. In other words, it's like a mall. There are many buyers and many sellers. I'm torn about how to model the sellers. Key facts: There won't be many sellers. Perhaps less than 20 sellers in total. There will be many buyers. Hopefully many thousands :) I already have...

How can I find all records for a model without doing a long list of "OR" conditions?

I'm having trouble composing a CakePHP find() which returns the records I'm looking for. My associations go like this: User ->(has many)-> Friends , User ->(has many)-> Posts I'm trying to display a list of all a user's friends recent posts, in other words, list every post that was created by a friend of the current user logged in. T...

How should I model associations between classes.

I am modelling the domain model in my application. Obviously, some of the object relationships are assocations, but those associations also have attributes. For example: Foo can have one-to-many Bars. However, the association has attributes, such as a date range for how long that association is valid. So, the way I have done this is...

Ruby on Rails: Best way to tie together two models that correspond one to one

If I have two models that are guaranteed to have a one-to-one correspondence, i.e. if one is created, I will always also need the other, and if one is deleted, I will also want to get rid of the other, what's the best way to tie them together? I see that the has_one/belongs_to :dependent method takes care of the deletions, but I don't s...

Rails: associate model with two of its kind

hi all, im trying to do this: class Event < ActiveRecord::Base belongs_to :previous_event has_one :event, :as => :previous_event, :foreign_key => "previous_event_id" belongs_to :next_event has_one :event, :as => :next_event, :foreign_key => "next_event_id" end because i want to enable the user to repeat events and change mult...