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