habtm

RSpec testing relationship logic

Hi, I'm testing the following: Account class Account < ActiveRecord::Base has_many :ownerships has_many :brands, :through => :ownerships end Ownership join model class Ownership < ActiveRecord::Base belongs_to :brand belongs_to :account end Test it "should be able to apply for brand ownership" do account = Account.cre...

HABTM, or multiple belongs_to?

I'm teaching myself Rails, and as a test project I'm mocking up a simple question/answer app similar to stackoverflow. In my simplified version I have: questions answers users (the authors of questions and answers) I get that answers belong to questions. What's the proper relationship between users and questions? What's the proper re...

How to create a rails habtm that deletes/destroys without error?

I created a simple example as a sanity check and still can not seem to destroy an item on either side of a has_and_belongs_to_many relationship in rails. Whenever I try to delete an object from either table, I get the dreaded NameError / "uninitialized constant" error message. To demonstrate, I created a sample rails app with a Boy c...

Rails trying to send the id for a habtm model join table?

Hi, So I have two rails models - user and role - each specified with a habtm and a join table of users_roles. When I save from my user form, which has checkboxes for which roles to choose, rails is trying to manually insert a value into the id column of the join table. This doesn't make sense to me, as the id column should be set to au...

Rails - HABTM relationship...Storing Checkbox Values from Users

Hi..Im trying to figure out this HABTM relationship issue to store in the interests of users within my database. The interests table has a list of different interests with id and name (i.e: id=1 , name = 'Music') I have a users model => user.rb has_and_belongs_to_many :interests and an interests model => interest.rb has_and_belongs...

HABTM Relationships and the Join Table

I'm trying to connect the values of two join tables that I have and show the results based on a conditional relationship...and i'm having some problems I have a Users Model(:name, :password, :email), and Events model(:name, :etc) and Interests model (:name) I created about 5 records in each model. Then I created two join tables -> Use...

HABTM Relationship and Named Scopes

I've been working on this for a while now and I cant seem to find where there error. I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model (:name) [>all singular<] Then I created two join tables -> UsersInterests and EventsInterests; each not containing a primary key and only comprised of the us...

What is the fastest way to create mass HABTM associations in Rails?

...

CakePHP is updating when it should be inserting a HasAndBelongsToMany model.

Hello! I have a small problem. I am making a site that has Tags and Questions. I have a Question model, Tag model, QuestionsTag model, everything fits together nicely. The user upon asking something puts the tags in the field seperated by a space (foo bar baz) much like on stackoverflow.com. Now, here is the code to check if a tag alre...

CakePHP HABTM: Editing one item casuses HABTM row to get recreated, destroys extra data

I'm having trouble with my HABTM relationship in CakePHP. I have two models like so: Department HABTM Location. One large company has many buildings, and each building provides a limited number of services. Each building also has its own webpage, so in addition to the HABTM relationship itself, each HABTM row also has a url field where ...

CakePHP - HABTM - adding multiple tags to multiple points

I am trying to 'tag' multiple 'points' with multiple tags. I'm tagging my single points successfully. Unfortunately, when i try and use a tag, such as 'test2' on another point as a tag it is either giving me a duplicate entry error if i have my 'unique' set to false or if 'unique' is set to true, it will del my tag for all other points ...

CakePHP and HABTM Tag Filtering

I am wrestling around a bit with CakePHP HABTM relationships, and I've gotten stuck trying to do a seemingly simple task. I have many Camps and many NewsItems. Each NewsItem could be relevant to any of the camps, so when a user creates a NewsItem, they check which Camps the item is for. That's the idea. So... I would like to incorpo...

rails HABTM joins and inconveniences

I have a working HABTM association between the models Posts and Users... the posts_users table is as advertised and both have the necessary has_and_belongs_to_many in their model.rb And if I use User.find(1).posts it will find all the posts with the valid username My question is how to deal with this situation. I want to use user.po...

Testing HABTM associations with rails/cucumber.

How am I supposed to test the typical User <-habtm-> Groups story. My Users and groups are created with factory_girl, it means I don't know the group id so I cannot ask webrat to check the checkbox. Thank you for any webrat steps hints ...

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...

Rails Nested editing form for self-referential HABTM Active Record Object

OK, this one is a doozy. I have an ActiveRecord object that, among other things, includes a relationships as follows: class Sample < ActiveRecord::Base has_and_belongs_to_many :related_samples, :class_name => "Sample", :join_table => "related_samples", :for...

Rails Single Table Inheritance with HABTM Fixture in unit testing returning NoMethodError: undefined method `singularize'

Imagine a model structure as follows: models/cross_sell_promotion.rb class CrossSellPromotion < Promotion has_and_belongs_to_many :afflicted_products, :join_table => :promotion_afflicted_products, :foreign_key => 'promotion_id', :association_foreign_key => 'product_id', :class_name => 'Product' has_and_belongs_to_...

Making HABTM relationships unique in CakePHP

I have two models, called Book and Tag, which are in a HABTM relationship. I want a couple (book, tag) to be saved only once. In my models I have var $hasAndBelongsToMany = array( 'Tag' => array( 'className' => 'Tag', 'joinTable' => 'books_tags', 'foreignKey' => 'book_id', 'associationForeignKey' => '...

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...

cakephp paginate multiple habtm

hi guys, i have multiple habtm like these : // User model var $hasMany = array('Post'); // Post model var $hasAndBelongsToMany = array('Category', 'Tag'); // Category model var $hasAndBelongsToMany = array('Post'); // Tag model var $hasAndBelongsToMany = array('Post'); I tried to fetch all post along with its user and tag...