鉴于我们有以下两个表,其中type_id引用了questionType中的一行:
题
id | type_id | description
---+---------+------------
1 | 1 | A nice question
.. | .. | ..
Run Code Online (Sandbox Code Playgroud)
问题类型
id | name
---+----------------
1 | Multiple-choice
.. | ..
Run Code Online (Sandbox Code Playgroud)
使用以下Eloquent模型:
class Question extends Model {
public function type() {
return $this->hasOne( 'QuestionType', 'id', 'type_id' );
}
}
class QuestionType extends Model {
}
Run Code Online (Sandbox Code Playgroud)
如何添加引用现有问题类型的新问题,而无需手动执行任何有关ID的操作?例如,以下工作,但是丑陋的imo因为我必须手动分配相应的问题类型id:
$q = new Question;
$q->type_id = 1; // Multiple-choice
$q->description = 'This is a multiple-choice question';
$q->save();
Run Code Online (Sandbox Code Playgroud)
有人会认为有一种方法可以让ORM处理id-assignment(这不是用ORMs来避免这样的东西吗?),这有点像(这在Eloquent …
根据Homebrew安装说明,可以使用以下命令进行安装:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Run Code Online (Sandbox Code Playgroud)
这有效,但需要用户输入两次; 确认安装并在脚本调用的sudo提示符中:
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local
Password:
Run Code Online (Sandbox Code Playgroud)
Homebrew没有无人参与安装的参数,所以我能想到的唯一选择是以编程方式输入预期的数据.我试过使用expect,但我不能正确使用语法:
$ expect -c 'spawn ruby -e \"\$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)\";expect "RETURN";send "\n"'
ruby: invalid option -f (-h will show valid options) (RuntimeError)
send: spawn id exp7 not open
while executing
"send "\n""
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?