Displaying 10 results from an estimated 10 matches for "has_many_and_belongs_to".
2006 May 07
1
Find records not in join with has_many_and_belongs_to
I have a User and Topic model. A user subscribes to a topic, so there is a
many-to-many relationship between User and Topic. So my User model object
is using has_many_and_belongs_to :topics and vice versa. I want to find all
the topics that a user has *not* subscribed to. This is what I''ve got:
@user = User.find(params[:id])
@topics = Topic.find(:all,
:conditions => ["id not in (select topic_id from topics_users where
user_id = ?)", @user...
2006 Jan 23
1
Help with hmabt relationships
hey,
I want to have this table structure with users and groups
A user can be in more than 1 group and a group has more than 1 user.
class User < ActiveRecord::Base
has_many_and_belongs_to :groups
end
class Group < ActiveRecord::Base
has_many_and_belongs_to :users
end
I was wondering if i can do this
for group in user.groups
...do stuff
end
-AND-
for user in group.users
...do stuff
end
I need both loops, can i do that, or do i need another structure...
Thanks in advance
Nick
2006 Feb 10
4
Handling a relationship between users and newsletter subcriptions.
Hey Everyone!
I have a newsletter system that contains a multitude of different
newsletters. In this case three but the system allows the user to
add more. Every user can be subscribed to any amount of given
newsletters. So what I did was I created a user model, newsletter
model, and subscription model.
The subscription model belongs to one user and one newsletter.
However,
2005 Sep 16
5
Table belongs_to self - good idea?
...stock level and possibly its own price, the Variants
table would have the same structure as Products, apart from a link
back to the original Product.
Would it be a good idea to have a "product_id" column in the Products
table that links back to the parent product? In Rails, would I use a
has_many_and_belongs_to relationship? Or should I use my own SQL to
avoid confusing Rails?
Thanks for any help that anyone can offer.
--
Matthew Revell
www.understated.co.uk
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table
has another "non-joiny" attribute.
I went from this:
has_many_and_belongs_to :jobs, :join_table => ''tablename'',
:foreign_key => ''x'',
:association_foreign_key => ''y''
to this:
has_many :jobs, :through => ''model_name''
Should this work? I''m th...
2008 Dec 22
7
Help creating and using database
I have this problem.
I have a Job table in my db, and each job has many steps (table Step).
Is not possible to know how many steps a job has until it is created. So
when I create a new job I have a problem: I can not have a step_id in my
Job table, because it can be one step or more.
What can I do?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
2006 Jun 20
0
options_from_collection_for_select question
I am doing the recipe/category example, but with a
has_many_and_belongs_to relationship. To select categories for a
recipe, I have a select control. When editing, I want the proper
categories selected. In order to get it to work, I put this in my
_form.rhtml:
<select id="recipe_categories" name="recipe[category_ids][]" size="4"
mul...
2005 Dec 23
1
Emails that get sent out on various site actions
Hi,
I have a list of various "events" that emails should be sent out on.
Example: user registers with site, or a user takes a test.
And I want the admin user to be able to configure what email addresses
should receieve the emails that get sent out on the events. Example:
joe-TIA8ZjFfG1I@public.gmane.org and jane-+LBmYUDmh58@public.gmane.org get an email when a user registers, and
2012 Apr 23
1
Searching and returning arrays
...;fc[]", facility.id%>
<%= facility.description %>
</div>
<% end %>
<%= submit_tag "Search", :name => nil%>
(...)
<% @hotels.each do |hotel|%>
<h2> <%= link_to hotel.name, hotel %> </h2>
My hotels and facilities are a has_many_and_belongs_to relationship with
everything working. The facilities_hotels table is created with the
facility_id and hotel_id collums, and the facilities table has for
columns a facility_id and description(which is for e.g. pool, 24hroom
service etc)
The issue is in my model:
def self.search(params)
if pa...
2006 Jan 08
22
Putting it all in one place with Schemas
I''m still relatively new to ROR, but I like what I see with the
database-neutral approach of Schemas. In the spirit of keeping it
simple and minimizing the number of files and location of information,
does ActiveState currently allow me to go ahead and place other low
level model information such as validation requirements and associations
inside the schema rather than putting it in