This project is archived and is in readonly mode.
has_many : << method doesn't handle :conditions
Reported by Jérôme | July 29th, 2008 @ 09:58 AM | in 2.x
class User < ActiveRecord::Base
# Follow topics
has_many :subscriptions
has_many :bookmarks, :through => :subscriptions, :source => :topic, :conditions => "subscriptions.notification = 'f'"
has_many :notifications, :through => :subscriptions, :source => :topic, :conditions => "subscriptions.notification = 't'"
end
john.notifications << some_topic
INSERT INTO "subscriptions" ("topic_id", "notification", "user_id") VALUES(361323, NULL, 1638)
Expected sql would be:
INSERT INTO "subscriptions" ("topic_id", "notification", "user_id") VALUES(361323, "t", 1638)
( "t" for postgresql true boolean)
Comments and changes to this ticket
-
Tarmo Tänav September 18th, 2008 @ 06:14 AM
- State changed from new to wontfix
- Tag changed from 2.1, activerecord, has_many to 2.1, activerecord, has_many
This will never happen, we can't start parsing arbitrary conditions, conditions are meant only as read-only restrictions on an association.
You can however use :before_add callbacks to restrict what can be added to the collection.
-
Jérôme September 22nd, 2008 @ 06:38 PM
- Assigned user set to Tarmo Tänav
Sure, but in my example, the :before_add hook can only handle the Topic, not the Subscription. :(
-
Jeff Kreeftmeijer October 19th, 2010 @ 07:09 AM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>