datamapper / dm-is-list Goto Github PK
View Code? Open in Web Editor NEWDataMapper plugin for creating and organizing lists
Home Page: http://datamapper.org/
License: MIT License
DataMapper plugin for creating and organizing lists
Home Page: http://datamapper.org/
License: MIT License
Greetings,
I have the following models, and I am using dm-is-list to sort them:
class Section
include DataMapper::Resource
property :id, Serial
property :name, String, :length => 1..100
property :credits, String, :length => 1..10
has n, :courses, :through => Resource
is :list, :scope => [:program_id]
end
class Course
include DataMapper::Resource
property :id, Serial
property :subj, String, :length => 4
property :code, String, :length => 3..5
property :name, String, :length => 1..100
property :description, Text
property :credits, String, :length => 1..10
has n, :sections, :through => Resource
end
class CourseSection
include DataMapper::Resource
belongs_to :course, :key => true
belongs_to :section, :key => true
is :list, :scope => [:section_id]
end
I am unable to select a given course and move it, so I am moving the Course Sections. I can use CourseSection.move(position) without issue. My problem gets more complicated when I try to use move_to_list(sectionID, position).
dm-is-list is setting the position value to NULL (I have verified that position is being sent). I have even tried to use move_to_list(sectionID) with no position, and NULL is still saved to the database. Obviously, subsequent attempts to move the item after that fail.
I attempted to define the position property as not null but that just resulted in an error when it tried to save the null. Position should never be null. This is making the gem unusable for me at this time.
test case: https://github.com/FND/dm-is-list/compare/below_bug
the first .move :below
fails - yet it succeeds if first doing an arbitrary .move :above
Since the RSpec test case seems potentially confusing, here's a sample script that might make it clearer:
module DEBUG
def self.info
puts Animal.all(:order => :position.asc).map(&:id).join(" ")
end
def self.move(id, vector, ref_id)
puts Animal.get!(id).move vector => Animal.get!(ref_id)
end
end
5.times do |i|
name = "animal#{i}"
Animal.create
end
DEBUG::info # 1 2 3 4 5
DEBUG::move 5, :below, 1 # false
DEBUG::info # 1 2 3 4 5
DEBUG::move 5, :above, 1 # true
DEBUG::info # 5 1 2 3 4
DEBUG::move 5, :below, 1 # true
DEBUG::info # 1 5 2 3 4
When I tried use dm-is-list with datamapper 1.3.0beta I error message with inherited hook.
Below I past part of necessary error message:
/.../gems/dm-core-f51603618654/lib/dm-core/support/hook.rb:169:in register_hook': inherited class method does not exist (ArgumentError) from /.../gems/dm-core-f51603618654/lib/dm-core/support/hook.rb:353:in
install_hook'
from /.../gems/dm-core-f51603618654/lib/dm-core/support/hook.rb:72:in after_class_method' from /.../gems/1.9.1/bundler/gems/dm-is-list-6826cd2647bf/lib/dm-is-list/is/list.rb:297:in
is_list'
Removing dm-is-list from model and application fixes this, but of course eliminates all dm-is-list functionality
Since the position field will probably be constantly used for ordering, it might be nice to change the property definition to
property :position, Integer, :index => true
is it possible to have multiple TODO lists per user (for user/todo example)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.