I used this example from the read me (using my own tables / columns) and it
works fine. Foreign key picks up the parent table primary key. I did this
in bin/sequel.
post = Post.create(name: 'hi!')post.comments
comment = Comment.create(text: 'hi')post.add_comment(comment)
However in my app code, trying to do the same thing in an iteration, the
'add_comment' throws
the error - `block in grab_files': undefined method `add_folder' for
nil:NilClass (NoMethodError)
Here is the method (it's ugly, and perhaps the error is do to some screwy
logic). To explain though the way the code traverses is it picks up the
folder path and then the individual files, in other words they should be in
order. First path, then a bunch of folders, then it should start the cycle
again.
Here is the classes -
class Path < Sequel::Model
plugin :validation_helpers
one_to_many :folders
def validate
super
validates_presence [:path]
end
end
class Folder < Sequel::Model
many_to_one :path
end
And here the logic -
def grab_files
music_list = Dir.glob("/vagrant/TestRails/Music/**/*")
music_list.each do |x|
if File.ftype(x) == "directory"
path = Path.create(path: x)
path.folders
elsif File.ftype(x) == "file"
folder = Folder.create(folder_name: (File.basename(x)))
path.add_folder(folder)
end
end
end
Ok, thanks for any help in advance. As I say, still wondering if my logic
is doing me in. I did use the code though to print out to a regular file
and that was fine.
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.