associations

1 has_many:.., :through and 1 has_and_belongs_to_many: .. problem??

The following are the models and association. class Vendor < ActiveRecord::Base attr_accessible :name, :address_attributes has_many :campaigns has_many :clients, :through => :campaigns end class Client < ActiveRecord::Base attr_accessible :name has_many :campaigns has_many :vendors, :through => :campaigns end class Campaig...

has_many relation doesn't seems right or logical in business perceptive, needed some thing like belongs_to_many?

My situation is like this. Company has many users and users may belongs to many companies. And current implementation is something like below. class Company has_many :employments has_many :users, :through => :employments end class Employment belongs_to :company belongs_to :user end class User has_m...

CakePHP access indirectly related model - beginner's question

Hi everyone, I am writing a CakePHP application to log the work I do for various clients, but after trying for days I seem unable to get it to do what I want. I have read most of the book CakePHP's website. and googled for all I'm worth, so I presume I am missing something obvious! Every 'log item' belongs to a 'sub-project, which in...

How do I create a type of compression that my software can read / write? My software only.

I am working on a project that requires programmatically distributing a compressed file that in a format that is associated with my software. I am writing the software in Python. I would use .zip, but I don't want to overwrite any previouse filetype associations. ( with zip utilities ) ...

Grails - Removing an item from a hasMany association List on data bind?

Grails offers the ability to automatically create and bind domain objects to a hasMany List, as described in the grails user guide. So, for example, if my domain object "Author" has a List of many "Book" objects, I could create and bind these using the following markup (from the user guide): <g:textField name="books[0].title" value="...

Rails ActiveResource Associations

I have some ARes models (see below) that I'm trying to use associations with (which seems to be wholly undocumented and maybe not possible but I thought I'd give it a try) So on my service side, my ActiveRecord object will render something like render :xml => @group.to_xml(:include => :customers) (see generated xml below) The models...

ActiveRecord find all parents that have associated children

I don't know why I can't figure this out, I think it should be fairly simple. I have two models (see below). I'm trying to come up with a named scope for SupplierCategory that would find all SupplierCategory(s) (including :suppliers) who's associated Supplier(s) are not empty. I tried a straight up join, named_scope :with_suppliers, :...

current_user and Comments on Posts - Create another association or loop posts? - Ruby on Rails

I have created a blog application using Ruby on Rails and have just added an authentication piece and it is working nicely. I am now trying to go back through my application to adjust the code such that it only shows information that is associated with a certain user. Currently, Users has_many :posts and Posts has_many :comments. When...

named_scope or find_by_sql?

I have three models: User Award Trophy The associations are: User has many awards Trophy has many awards Award belongs to user Award belongs to trophy User has many trophies through awards Therefore, user_id is a fk in awards, and trophy_id is a fk in awards. In the Trophy model, which is an STI model, there's a trophy_type colu...

Rails nested association issue

Ok, so I'm new to both Ruby and Rails and I'm trying to do what I believe is called a nested association (please correct me if this is the wrong terminology). I currently have a User model and a Domains model and I have many to many associations setup (using has_many :through) between the two, and this works fine. I now want to extend t...

defining class relationships in c# and visual studio 2010

Hey guys, in Visual Studio 2010 I can point to a bunch of classes and create a diagram. However, the diagram by default doesn't recognize any relationships between the classes, except inheritance and implementations. Is there a way, ideally by using Attributes, to define class and property relationships and associations in such a way t...

Rails find all with association

I have what I think is a very simple problem (famous last words)... I have a Category model that has_and_belongs_to_many Events. I want to construct a simple and efficient query that finds all categories that have 1 or more events. (using Rails 3) I'm sure I'm having a dumb moment here - any help appreciated :) ...

How to create a view to manage associations between HABTM models? (Rails)

Hello, I am using Ruby on Rails and need to create a view that allows the creation of records through a HABTM relationship to another model. Specifically, I have the following models: Customer and ServiceOverride, and a join table customers_serviceoverrides. Using the customer view for create/update, I need to be able to create, update a...

Why is my model firing the validation at the wrong time?

In my edit action of my employees_controller I have this line of code: #Employee#edit 69: if @employee.user.person.addresses.length == 0 70: @employee.user.person.addresses << Address.new 71: end which should add a blank Address if there are none so it will show up in my edit erb file. That way if there were no Addresses associated ...

Rails :dependent => :destroy VS :dependent => :delete_all

In rails guides it's described like this: "Objects will be in addition destroyed if they’re associated with :dependent => :destroy, and deleted if they’re associated with :dependent => :delete_all." Right, cool. But what's the difference between being destroyed and being deleted? I tried both and it seems to do the same thing. ...

Rails 3 find all associated records has_many :through

I would like to list all posts that are connected with some specific category and classroom. I have: class Post < ActiveRecord::Base has_many :category_posts has_many :categories, :through => :category_posts has_many :classroom_posts has_many :classrooms, :through => :classroom_posts end class Category < ActiveRecord::Base h...

Ruby on Rails - Primary and Foreign key

Hey, I am creating a site in Ruby on Rails, I have two models a User model and a Transaction model. These models both belong to an account so they both have a field called account_id I am trying to setup a association between them like so: class User < ActiveRecord::Base belongs_to :account has_many :transactions end class Trans...

How can i generate mongoid.yml config in Rail 2.3.5?

As the title says, how can i generate the default mongoid.yml config file on Rail 2.3.5? I try to use te ´rails generate mongoid:config´ command but it just generates a new app. And also, i would like to use has_many in mongoid without embeding the associated model in the same field. I would like them to be in seperate fields and associ...

Ruby on Rails Join Table Associations

Hey, I have a Ruby on Rails application setup like so: User Model has_and_belongs_to_many :roles Role Model has_many :transactions has_and_belongs_to_many :users Transaction Model belongs_to :role This means that a join table is used called roles_users and it also means that a user can only see the transactions that have been ...

How extensive is an Object in CakePHP model linkage?

I was hoping someone with an understanding on CakePHP could shed some light on a question I've been having. Here's my scenario, I have a User this User has a Company which in turn has many Department and many Address. If I were to get a User could I expect to have access to the Company and all models associated with that Company? So wo...