Argumenterror: Unknown Key: :Conditions. Valid Keys Are: :Class_Name, :Class, :Foreign_Key

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



Leave a reply



Submit