ArgumentError: Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key
You should change the code in User
model to
class User < ActiveRecord::Base
has_many :user_friendships
has_many :friends, -> { where(user_friendships: { state: "accepted"}) }, through: :user_friendships
has_many :pending_user_friendships, -> { where(state: "pending") }, class_name: 'UserFriendship', foreign_key: :user_id
has_many :pending_friends, through: :pending_user_friendships, source: :friend
end
Rails association that specifies foreign key and where options
The lambda -> { ... }
has to be the first argument (or second depending on how you count it)
has_many :library_collection_books,
-> { where collection_type: 'library'},
foreign_key: :user_id,
class_name: 'CollectionBook'
string' can't be used to index type '{}'
items: object[],
While technically it is a JavaScript object, the type can be better. For Typescript to correctly help you identify mistakes when accessing objects properties, you need to tell it the exact shape of the object. If you type it as object
, typescript cannot help you with that. Instead you could tell it the exact properties and datatypes the object has:
let assistance: { safe: string } = { safe: 1 /* typescript can now tell this is wrong */ };
assistance.unknown; // typescript can tell this wont really work too
Now in the case that the object can contain any sort of key / value pair, you can at least tell typescript what type the values (and the keys) have, by using an object index type:
items: {
[key: string]: number | string,
}[]
That would be the accurate type in the case given.
Related Topics
Problem Installing Ruby 1.9.2 on MAC Os Lion
Generating a Race Condition with Mri
Find Keep Duplicates in Ruby Hashes
How to Start Ruby 1.9 Without Rubygems
Ruby: Why Does '#Hash' Need to Overridden Whenever '#Eql' Is Overridden
Validate Japanese Character in Active Record Callback
Rvm Install Ruby-1.9.3-P286: Error Running 'Make -J 9' (Osx: Mountain Lion)
Exec Onlyif Registry Value Is Not Present
Closures and for Loops in Ruby
Rails Format Validation -- Alphanumeric, But Not Purely Numeric
When to Use Association Extensions VS Named Scopes
Overriding Model in Gem, Adding Callback and Methods