Displaying 20 results from an estimated 40000 matches similar to: "HABTM associated record presence validation"
2006 Jun 20
2
habtm, multi select, and validation
Greetings -
I''m trying to find the most efficient, "Rails" way to solve the
following problem. It''s in two parts, but I think the solution is
somewhat related:
I have Recipe and Category model related by HABTM. I would like to
1.) Validate the *number* of categories associated with a recipe, say a
minimum of 1 and a max of 3. (So validates_associated will not
2006 Jul 12
1
odd habtm behavior? or is it me?
Hello List,
I''m a bit spent on this problem, and my code might be whack. I seem to be
encountering a problem where the primary key on a join table is not being
resolved correctly. I will elaborate after some code bits. I am creating
the join table using migrations, and relevant model code is this:
class Post < ActiveRecord::Base
has_and_belongs_to_many :records
2006 Jan 04
2
Updating Attributes in a HABTM Join Table
Is there a way to update attributes in a HABTM join table? Right now
I am deleting the join and then recreating it with new attributes.
I have a table "categories" and another table "items". They are both
HABTM with the join table "categories_items" between them. If an item
is joined to a category once, no problem, we create the join. But if
an item is
2006 Feb 14
1
Another HABTM Question
Hi there,
I have a question on what would be the best way to save a HABTM model.
A posting habtm categories, and a category habtm postings.
class Category < ActiveRecord::Base
has_and_belongs_to_many :postings
end
class Posting < ActiveRecord::Base
has_and_belongs_to_many :categories
end
In my blog_controller, where the actual posting is saved, is where I
think I''m
2006 May 01
4
Find rows with associations in habtm
This may have been asked/answered before - if so, i apologise...
I have the following table layout in a habtm relationship:
------------ ----------------------- --------------
| products | ----| categories_products |-----| categories |
------------ ----------------------- --------------
What would be the best way to pull out all the products for a given
category? At the
2006 Jun 05
7
Is HABTM Dying?
For a while, I''ve been getting that HMT is replacing HABTM. It appears that
HMT can do all of what HABTM can do and more. The question is: Should I stop
using HABTM? Let''s take a simple case:
A case has many categories
For a given category, there are certain valid statuses
Category
has_and_belongs_to_many :statuses
Status
has_and_belongs_to_many :categories
Question:
Is
2006 Feb 23
1
Pretty HABTM check boxes
I''m 100% positive this has come up multiple times before. I just
can''t find it for some reason. I''ve got a HABTM relationship, we''ll
just say Item HABTM categories. When I edit an Item via a form, I''d
like there to be check boxes for all the categories, and they''ll
obviously be checked if an Item has a relationship with a particular
2006 Jun 29
2
HABTM with multiple select list
Hello,
I am very new to ruby and need to create my first HABTM with multiple
select list.
I am having problems saving data in the middle(linking)
table.
1. titles can have multiple categories
2. categories can have multiple titles
Categories, titles and categories_titles tables are created.
----- title_controller.rb--
def new
@title = Title.new
@categories =
2006 Jun 29
0
HABTM and select form helper
I am very confused about HABTM and a form select statement that I need to
implement.
I have two objects - Person which has the following fields:
id, firstname, lastname, email
Category which has the following fields:
id, name
A person HABTM categories and also the reverse. I have setup the join table
using a migration. All that went well.
Two questions - If I want to edit a person, how do I
2005 Dec 20
0
Problem destroying in unit tests with HABTM
Hi converted two of my models to HABTM today but I am having a real
hard time getting my unit tests to pass now. Specifically, when I
destroy a record I get this error:
...many many lines of this above...
(eval):4:in `destroy_without_habtm_shim_for_categories''
(eval):4:in `destroy_without_habtm_shim_for_categories''
(eval):4:in
2006 Aug 11
0
Paginating HABTM?
Is there an easy way to paginate HABTM? Something like (which doesn''t
work):
@pages, @directories = paginate :directories,
:include=>:categories,
:per_page=>ITEMS_PER_PAGE
directories and categories have an HABTM association.
Joe
--
Posted via http://www.ruby-forum.com/.
2006 Jul 27
1
importing data with migration for habtm
I have 2 tables: products and categories. They are both linked by a
habtm association. I have a fixture to import all the data in each table
but I dont know how to import the data in the categories_products table
since that table has no model, so I cant use that code:
f = Fixtures.new(Category.connection, # a database connection
"categories", # table name
2006 Jun 30
2
how to HABTM with STI ??
Hello all
This is my first post so excuse the basic question. (and any repeats I just
got an email saying this post was too big so I have re-submitted a smaller
version)
I was following the thread on
http://lists.rubyonrails.org/pipermail/rails/2006-May/038988.html regarding
the STI on HABTM for RoR.
I have a very similar problem and was hoping for some help.
I have the
2011 Apr 16
0
adding HABTM association while creating a record
Hello Experts,
I have a HABTM association as followed:
class Account < ActiveRecord::Base
has_and_belongs_to_many :user
end
class User < ActiveRecord::Base
has_and_belongs_to_many :type
has_and_belongs_to_many :account
end
class Type < ActiveRecord::Base
has_and_belongs_to_many :user
end
I have the following query;
I Have a parent user who is creating another user under its
2008 Dec 16
1
Callback when objects connect as a habtm relationship
If Product and Category models are in a habtm relationship, i.e.
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end
I want a piece of code to be executed every time a product is connected to a
category.
Where do I put this code? Which callback (and on which model) will be
triggered?
Any
2006 Apr 29
5
HABTM - how to insert join row when associated rows exist
I have successfully used HABTM to create a many-to-one-to-many set of
rows in one step. Now, if two objects I want to associate already exist,
how do I create the join row? The Agile book mentions the
''push_with_attributes'' method. The text says this method is useful for
adding additional attributes to the join row (in the example a ''read_at''
timestamp). I
2009 Dec 30
4
Validating the presence of two associated objects from both models
I have a model “Conversation” and a model “Leader”. A Conversation is always led by exactly 1 Leader.
I’ve overridden Conversation’s “validate” method to validate the presence of an associated Leader model.
If I add a similar validation to the Leader model, however, Conversations can no longer be saved on creation because the Leader model is invalid.
On creation of both a new Conversation and
2006 May 05
4
STI and HABTM
Hey gang,
How does STI work with HABTM?
For instance...let''s say I have the following models
-----
Category < ActiveRecord::Base
Item < ActiveRecord::Base
Product < Item
Deal < Item
-----
Each product or deal can have categories. Would I then setup Item with
has_and_belongs_to_many :categories, then create a table categories_items
??? Is there a better way to do it?
2006 Jun 28
0
habtm and multiple-option select boxes
I''ve got a fairly basic has_and_belongs_to_many setup, with a Business
model and a Category model. In the admin functionality for the Business,
I''d like to have a multiple select box showing all of the Categories, with
included ones selected, etc.
I''m stumped as to how to do it, though - it seems like there should be an
easy way, but I''m missing it looking
2006 Jan 02
3
Selecting conditionally from HABTM
Hello,
I was wondering whether there is a nice Rubyesque way of selecting
from a pair of HABTM models where one of them is inherited from
another object.
Here is the situation:
I have a ''posts'' table from which ''replies'' and ''articles'' are
inherited. Articles have_and_belong_to_many categories, but neither
posts nor replies do (it just does