similar to: Queries with has_and_belongs_to_many relationship

Displaying 20 results from an estimated 1000 matches similar to: "Queries with has_and_belongs_to_many relationship"

2006 Jan 09
3
Selecting a subset of a table with DRY
Hello, I have table called ''listings.'' There are a certain combination of properties which make a listing viewable (e.g., it is confirmed, has been authorized, hasn''t expired, etc.). Each listing has one and only one category. I want to be able to do things like Listing.find_viewable(...) and Category.find(...).viewable_listings, but I see no way to do this
2007 Jun 23
3
has_and_belongs_to_many and dynamic find
Hi Just curious if anyone can explain why using a dynamic find fails to work with << operator I have standard habtm relationship class User < ActiveRecord::Base has_and_belongs_to_many :roles Now when I assign a Role via << after saving the new User I get wierd behaviour but only when using the dynamic version of find i.e @user = User.new(p) if @user.save #
2005 Mar 06
4
has_many and order
Hi all, if I have a has_many and belongs_to relations like this category has many articles article belongs to category is there a way I can specify the order of articles when pulling them up with @some_category.articles ? Many thanks in advance! -- Nicky
2006 May 23
2
Ordinalizing a date
I''m trying to use the ordinalize() method to ordinalize a day. Here''s how far I''ve gotten: @reportday = Time.now.at_beginning_of_week.strftime("%d").to_i @ordinalized_reportday = "#{@reportday}".ordinalize I was thinking it wasn''t working because the date is being returned as a string, however I added the .to_i and still it returns an
2005 Nov 05
3
Keeping the queries down...
I''m trying to ensure that I keep the number of queries down a bit. If I have two model (lets call them Foo and Bar). They have a many to many relationship. Now I want to get (and paginate) records from Bar that are related to a certain record in Foo. For example I want all records from Bar whose name starts with ''C'' and are related to record Foo whose name is
2005 Mar 01
0
has_and_belongs_to_many problem
I''m having a problem with a has_and_belongs_to_many (habtm) association between two models with extra attributes. I''m writing a comic book database, and each issue has many creators on it. Thing is, some creators perform multiple duties. They may write one issue, draw another, etc. However, if I add a creator twice to an issue and try to delete it, it removes both creators:
2006 Apr 06
3
has_and_belongs_to_many find
Say I have a post model that has_and_belongs_to_many :categories, and a category model that has_and_belongs_to_many :posts. So I have a categories_posts table to do the join. That''s all find and dandy. However I want to be able to find all the posts that belong to a specific category. I tried Post.find_by_category(:id) but that doesn''t work. Does anyone have any insight?
2006 May 26
0
has_and_belongs_to_many with fk constraints?
Hi folks, I''m wondering if it''s possible to use foreign key constraints on the join tables of a has_and_belongs_to_many relation. Specifically, I get this error when I try and delete a model I''m using, named saved_search, which is many-to-many with neighborhoods. Any ideas? Thanks for any help. :-) -Eric Code: @saved_search.destroy Error: Mupdate or delete on
2006 Jan 16
0
belongs_to with has_and_belongs_to_many
I''m having a problem with belongs_to and has_and_belongs_to_many. Here''s a brief summary of the models involved: class Member < ActiveRecord::Base set_primary_key ''member_id'' has_and_belongs_to_many :projects, :join_table => ''projects__members'' has_many :projects, :foreign_key => ''created_by'' end class
2005 Oct 05
0
has_and_belongs_to_many on legacy DB
I am working with mapping ActiveRecord onto a legacy database. All is going well (using set_table_name, set_primary_key, etc), but I can''t get my many<=>many relationships to work. My contrived example of the situation: Student has_and_belongs_to_many Teachers. This is mapped via table student2teacher where the foreign keys are studentId and teacherId. The primary key in Student
2006 Mar 07
1
has_and_belongs_to_many tags
I''m trying to create a search where I can find pages by their tag name. Here''s a sample of my code (not working). @tags = Page.find(:all, :conditions => ["#{:tag.name} LIKE ?",''%'' + @params[''searchtags''] + ''%'' ]) My enviroment: I''ve got a table called tags, and a table called pages, both with a
2006 Mar 09
2
has_and_belongs_to_many -- how to create test fixtures?
Hallo -- can anyone offer me any pointers as to I should handle many-to-many relationships in Rails tests? Cheers, doug. -- Posted via http://www.ruby-forum.com/.
2006 Jan 03
0
has_and_belongs_to_many include problem
hey, i have users who are in groups, and i have a search form, where i can search on group, user lastname, and user firstname. All this is also with pagination. these are my models class User < ActiveRecord::Base has_and_belongs_to_many :groups end class Group < ActiveRecord::Base has_and_belongs_to_many :users end in my controller i do this THIS works (but in need pagination) @users2
2005 Dec 14
0
how to get these records in has_and_belongs_to_many relation
hey, i my database i have users and groups, each user can get in different groups my db structure: table groups: id, name, basegroup, firm_id table users: id, firstname, lastname, email table groups_users: group_id, users_id my relation is a many to many: class Group < ActiveRecord::Base has_and_belongs_to_many :users end class User < ActiveRecord::Base has_and_belongs_to_many
2005 Mar 02
1
Cleaning up has_and_belongs_to_many?
Does has_and_belongs_to_many know to delete an object when the last reference to it is removed? In my case I have Receiver <<->> Message (with a join table of course), but have noticed that when the last receiver removes a message from the association the message still exists. Before adding code to manage this situation I want to check to see if I am missing something? --
2007 Aug 07
0
has_and_belongs_to_many polymorphic question
I''ve got a situation where I''m trying to model the following relationship: a ''page'' has multiple lineitems a ''lineitem'' can be either a ''page'' or a ''entity'' The ''lineitem'' looks like it should be polymorphic but the ''page'' and ''lineitem''
2006 Dec 25
2
how to insert data using has_and_belongs_to_many
I''am newbie in RoR, so my question might look stupid, but I stuck in one thing. I''ve created 3 tables: users{ id, user } books { id, book } books_users{ book_id, user_id} Model class Book< ActiveRecord::Base has_and_belongs_to_many:users I can''t figure out how to insert data to the books_users table. For example users post info about new book and information
2006 Nov 09
2
help with join tables and has_and_belongs_to_many
Hi, I have a user model and a privilege model. They have the has_and_belongs_to_many relationship. Here are the model defs: class User < ActiveRecord::Base belongs_to :status has_and_belongs_to_many :privileges end class Privilege < ActiveRecord::Base has_and_belongs_to_many :users end Now I have a migration script to create the join table and populate a few users with some
2006 May 11
1
ActiveRecord collection_select and has_and_belongs_to_many
Hello everyone, first post to the list and a relative newbie to Rails development. Done quite a bit of JSP, PHP, HTML, XML etc and thought I would kick the tires on Rails to see if it can speed up development for internal applications. Anyway, I am running into a problem that is just driving me crazy and everything I read on the net doesn''t seem to help. I was hoping someone here might
2012 Sep 08
3
Polymorphic has_and_belongs_to_many association
Hi, I''m currently having the situation where I have to implement a polymorphic has_and_belongs_to_many by introducing an in between model that handles all the "has_many :as" and "belongs_to :polymorphic" association implementations... and is not doing anything else. Thing I don''t like it here is, I am unnecessarily loading AR instances only to execute SQL