我在使用rails中基于动态属性的查找器时遇到了问题。它们似乎不适合我的模型。
class Person < ActiveRecord::Base
belongs_to :team
end
class Team < ActiveRecord::Base
has_many :people
end
因此,在脚本/控制台中,要查找具有ID为1的人员的团队,我应该能够执行以下操作:
>> Team.find_by_person_id(1)
我得到了错误:
NoMethodError: undefined method `find_by_person_id'
这
我有以下几种型号:
class UserProfile(models.Model):
user = models.OneToOneField(User)
class Site(models.Model):
user = models.ForeignKey(User)
site_name = models.CharField(max_length=128, blank=False, null=False)
class Team(models.Model):
site = models.ForeignKey(Site)
team_member_name
假设我有以下类型类
class Silly (t :: * -> *) where
-- details
我希望能够表达以下约束,但我不确定这是否可能。
class (Silly s) => Willy (s t) where
-- details
基本上,我想对类型构造函数施加一个约束,而不是整个类型。这句话能表达吗?我甚至不知道这种约束会被称为什么,所以谷歌一直没有帮助。
编辑:我有一个数据类型
data Reasoner logic atoms a = Reasoner { unReasoner :: MassAssignment atoms -> a
在一段代码中,我想做一种元编程,我想要定义一个函数,我可以将它作为参数传递给某些类型(所以不是类型的实例,而是类型本身)。
我想把接受的类型限制为某个类或它的后代。
我试图通过以下代码来实现这一点:
class ABase {}
class AConc extends ABase {}
class B {}
interface IAClass {
new(): ABase;
}
function meta(AT: IAClass) {
console.log('foo');
}
// This gives an error, as it should.
meta
我对通过get-value生成模型值有一个问题。如果我试图获得一个数组的值,我将得到一个包含内部z3常量的值,但没有打印出来。我知道get-model会打印这些常量,但我还是坚持使用get-value。
下面是一个例子(我在rise4fun上试用过):
(declare-const b (Array Int Int))
(declare-const a (Array Int Int))
(assert (= (store a 1 2) b))
(check-sat)
(get-value (b a))
返回:
sat ((b (_ as-array k!1)) (a (_ as-array k