Лог чата на #dbix-class по поводу запроса с JOIN

Aug 10, 2007 19:08

irc://irc.perl.org/dbix-class Hello! I can’t select joined data from 2 tables. I have joined table ‘file’ and ‘filetype’ where file.filetype_id=filetype.id. I can find some row from ‘file’ ($file = $c->model(‘Dbase::File’)->search({$field => $name})->first;) but I can’t make query to 2 tables simultaneously. If I try add { ‘join’ => ‘filetype’, ‘+select’ => [ ‘filetype.mime’ ], ‘+as’ => [ ‘mime’ ] } as second parameter to search() (I saw example in perldocDBIx::Class::Manual: :Joining), I see error message: DBIx::Class::ResultSet::count(): No such relationship filetype at /usr/local/lib/perl5/site_perl/5.8.8/Devel/StackTrace.pm line 139.
What I do wrong?
Shoorick: and did you add a relationship named “filetype”?
Relations created dynamically at start of application.
then you need to find out what the relationship is called
cos its clearly not “filetype”
I use Catalyst: there is Helper, who create relations with names = names of tables in database.
Shoorick: are you sure? I think it has a debugging option so you can see what relationships it created
does he mean loader maybe?
ash: sounds like it

sounds like it is still a young technology
purL; shush!
“Shoorick” at 217.168.144.84 pasted “part of debug screen” (22 lines) at http://scsys.co.uk:8001/8949
I found 2 occurences of word “filetype” on debug screen
kinda hard to tell what that is with all the stuff you’ve removed
ash: any idea?
doesn’t look like its found the rel would be my initial rel
Shoorick: what helper are you usgin?
I’ve removed lines with names of another tables
must. stop. typing.
ash: hehe
script/teach_create.pl model Dbase DBIC::Schema Dbase create=dynamic dbi:mysql:db_name_here username_here password_here
if use create=static instead create=static, it will create many *.pm files with static definition of structure of database
nopaste the relevant create tablt stmts
Shoorick: those .pm files should give you the useful info about the relationships
Shoorick: you also removed too much of the debug output
leave it all in
full debug page contains >1700 lines :-\
that new make_schema_at from D::C::Schema::Loader that keeps track of the manual changes is awesome
renaud: it does?
* purl stays quiet
castaway: yes, it leaves you a room for changes that will be copied upon update
renaud: sneaky :)
much faster than dumping in a temp dir, diff-ing, and updating manually :)
“Shoorick” at 217.168.144.84 pasted “very BIG (1724 lines) debug screen” (1724 lines) at http://scsys.co.uk:8001/8950
* castaway has .pm files longer than that ‘;)
apeiron: I added your manual patch, thanks!
Shoorick: looks like the relationship you need is named ’filetype_id’ in the File class
filetype_id => { attrs => { accessor => “filter” }, class => “Dbase::Filetype”, cond => { “foreign.id” => “self.filetype_id” }, source => “Dbase::Filetype”, }
renaud++
may be try to create static modules?
Shoorick: no, use “filetype_id” where you have “filetype” in your join
static is good anyway, but it wont change the name of the rel ;)
mugwump: not sure I have a clue what you’re doing.. ;)
* castaway looks up Store::DBIC
Request now executed. But I don’t know how to get joined value. I’ll show code...
“Shoorick” at 217.168.144.84 pasted “Sample of code” (7 lines) at http://scsys.co.uk:8001/8951
print $file->filetype_id->mime
oops, sorry thats wrong
I can read some fields of table ‘file’, for example $file->name or $file->file. But I can’t read $file->mime: Can’t locate object method “mime” via package “Dbase::File” at /usr/home/as/wrk/teach/trunk/script/../lib/Teach/Controller/File.pm
print $file->get_column(‘mime’)
Shoorick: it doesnt magically create accessors for columns that are not in file
you need to use get_column for those
is that not in the Joining doc? if so I will fix it
Wow! It works! :-)
I hope so ;)
Thank you very much!
you’re welcome

db, sql, log, perl, dbix::class

Previous post Next post
Up