基本上我有以下架构,如果它们不存在我会插入记录.但是,当涉及到插入副本时,它会抛出错误,正如我所料.我的问题是,是否有一种简单的方法可以让Hibernate忽略实际插入重复项的插入?
CREATE TABLE IF NOT EXISTS `method` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
SEVERE: Duplicate entry 'GET' for key 'name'
Exception in thread "pool-11-thread-4" org.hibernate.exception.ConstraintViolationException: could not insert:
Run Code Online (Sandbox Code Playgroud) 基本上我需要为一个类获取一个常量,但是我没有该对象的实例,只有它的类.在PHP中,我会做constant(XYZ);
一个类似的方法来检索JAVA中的常量吗?
我需要它来促进动态getMethod调用
Class parameterType = Class.forName(class_name);
object.setProperty(field name, field value, parameterType);
Run Code Online (Sandbox Code Playgroud)
然后set属性方法将获取正确的方法并设置指定的属性,但是我不能使用int作为参数类型而不使用Interger.TYPE
我有嵌套集合的以下模型
var Mdl = Backbone.Model.extend({
initialize: function() {
// collection
this.col1 = new NestedCollection();
},
...
});
Run Code Online (Sandbox Code Playgroud)
我想在一个请求中发送集合中的模型和模型的数据,如下所示:
{
att1: val,
col1: [{obj1: val}, {...}]
}
Run Code Online (Sandbox Code Playgroud)
我不确定将请求中的数据交给嵌套集合(col1)的最佳方法.我做不到......
var Mdl = Backbone.Model.extend({
initialize: function() {
// collection
this.col1 = new NestedCollection(this.get('col1');
},
...
});
Run Code Online (Sandbox Code Playgroud)
...因为在初始化时调用模型的解析函数尚未调用,这意味着属性col1为空,我想到的另一个解决方案是监听父模型中的更改,如...
model.bind("change:tags", function() {
model.col1.refresh(model.get('col1'));
});
Run Code Online (Sandbox Code Playgroud)
然而,这个解决方案感觉有点沉重,可能会破坏任何
this.col1.bind("add", function() {})
Run Code Online (Sandbox Code Playgroud)
和
this.col1.bind("remove", function() {})
Run Code Online (Sandbox Code Playgroud)
集合上的功能设置.
有没有人知道这样做的"官方"方式?
谢谢.
我在视图中从模型内的集合中删除项目时遇到一些问题.基本上模型/集合结构如下:

基本上,当我尝试从子项视图中的子项集合中删除项目时,它实际上从集合中删除了正确的项目.然而,当我来坚持主模型时,项目似乎仍然在集合中.
这就是我的观点的结构:

主视图插入主模型所需的DOM节点,主模型为项目模型等创建新视图.所有视图都将主模型作为模型选项,如下所示:
new App.Views.MainModelView({
model : this.model,
el : $('#nodeID')
})
Run Code Online (Sandbox Code Playgroud)
唯一的区别在于子项目模型视图的创建,其中,由于视图和模板的可用性,我仍然传入主模型,但是我也传递了当前正在项目集合中的项目改性.看起来像这样:
new App.Views.ItemView({
model : this.model,
item : this.selectedItem,
el : $('#nodeID')
});
Run Code Online (Sandbox Code Playgroud)
在子项的视图init方法中,我执行以下操作:
this.item = (this.options.item) ? this.options.item : this.model;
Run Code Online (Sandbox Code Playgroud)
要从子项集合中删除子项,我执行以下操作:
removeSubItem : function(e) {
// get the id of the sub-item to be removed
var id = $(e.target).closest('tr').attr('data-id');
if (!id) throw "Could not retrieve data id";
// retrieve the sub-item from the collection
var subItem = this.item.subItems.get(id);
// remove the sub-item from the collection
this.item.subItems.remove(subItem); …Run Code Online (Sandbox Code Playgroud) 我有以下样式表结构:
/stylesheets
|
|-- /subfolder
| |
| + styles.css.scss
|
+ application.css.scss
Run Code Online (Sandbox Code Playgroud)
application.html.haml
= stylesheet_link_tag "application", media: "all"
= stylesheet_link_tag "subfolder/styles", media: "all"
Run Code Online (Sandbox Code Playgroud)
application.css.scss
@import "styleguide";
@import "styleguide/base/_all";
@import "styleguide/modules/_all-no-grid";
// Omitting rules not relevant to the problem
Run Code Online (Sandbox Code Playgroud)
styles.css.scss
@import "styleguide";
@import "styleguide/grid/_grid";
@import "styleguide/modules/_all-grid";
// Omitting rules not relevant to the problem
Run Code Online (Sandbox Code Playgroud)
styleguide文件存在于gem中vendor/stylesheets,在RoR引擎的帮助下为资产提供服务.
当我使用预编译资产在生产中运行我的应用程序时,我遇到了指向@import样式指南的问题.
File to import not found or unreadable: styleguide.
Load path:
Sass::Rails::Importer([omitted]/app/assets/stylesheets/local/styles.css.scss)
(in [omitted]/app/assets/stylesheets/local/styles.css.scss)
Run Code Online (Sandbox Code Playgroud)
styleguide本身没有问题,因为只要我subfolder/styles.css.sccs从application.css.scss …
我目前正在开发一种可安装的发动机.在发动机内我有以下两种型号:
module Ems
class Channel < ActiveRecord::Base
has_and_belongs_to_many :categories
end
end
module Ems
class Category < ActiveRecord::Base
has_and_belongs_to_many :channels
end
end
Run Code Online (Sandbox Code Playgroud)
这些是db迁移文件:
class CreateEmsChannels < ActiveRecord::Migration
def change
create_table :ems_channels do |t|
t.string :slug
t.string :name
t.timestamps
end
end
end
class CreateEmsCategories < ActiveRecord::Migration
def change
create_table :ems_categories do |t|
t.string :slug
t.string :name
t.text :strapline
t.timestamps
end
end
end
class CreateEmsCategoriesChannels < ActiveRecord::Migration
def up
# Create the association table
create_table :ems_categories_channels, :id => false do |t|
t.integer :category_id, …Run Code Online (Sandbox Code Playgroud) 我有一个关于在symfony任务中创建绝对URL的快速问题.基本上我有以下几点:
/**
* This function returns the link to a route
*
* @param $context context from which to create the config from
* @param $routingText this contains the text to be routed
* @param $object if we are generating an object route we need to pass the object
* @param boolean $absolute - whether to generate an absolute path
* @return string
*/
public static function getUrlFromContext($routingText, $object = null, $application = null, $debug = false,
$absolute = false, …Run Code Online (Sandbox Code Playgroud) 我试图将包含嵌入式集合的相当复杂的模型保存回关系数据库.由于嵌入式集合返回到服务器的数据包含足够公平的对象.然而,我在现有应用程序之上构建主干应用程序,并且必须以标量形式返回值才能重用服务器端代码.关于这个的最好的是什么,我正在考虑重写模型的toJSON函数,但我真的不应该这样.所以我能想到的另一种选择是覆盖同步方法并在那里进行.然而,即使这似乎也不对.我错过了什么或者正在覆盖同步方法是必要的邪恶吗?
关于可安装在导轨上的发动机的问题。首先这些是我正在使用的版本;
$ rails -v
Rails 3.2.1
$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
Run Code Online (Sandbox Code Playgroud)
我用这个创建了可安装的引擎:
$ rails plugin new testEngine --mountable
create
create README.rdoc
create Rakefile
create testEngine.gtestEnginepec
create MIT-LICENSE
create .gitignore
create Gemfile
create app
create app/controllers/testEngine/application_controller.rb
create app/helpers/testEngine/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/testEngine/application.html.erb
create app/assets/images/testEngine
create app/assets/images/testEngine/.gitkeep
create config/routes.rb
create lib/testEngine.rb
create lib/tasks/testEngine_tasks.rake
create lib/testEngine/version.rb
create lib/testEngine/engine.rb
create app/assets/stylesheets/testEngine/application.css
create app/assets/javascripts/testEngine/application.js
create script
create script/rails
create test/test_helper.rb
create test/testEngine_test.rb
append Rakefile
create test/integration/navigation_test.rb
vendor_app test/dummy
run …Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails rails-engines ruby-on-rails-3 ruby-on-rails-3.1
backbone.js ×3
javascript ×3
java ×2
ruby ×2
constants ×1
dynamic ×1
gem ×1
hibernate ×1
mysql ×1
php ×1
reflection ×1
sass ×1
symfony1 ×1