perl - How do I use add_to in Class::DBI? -


I'm trying to use class :: DBI with a simple parent -> maybe Relationships:

Code: Data: Company & gt; Table ('companies'); Data: Company- & gt; Columns (all = & q; qw / CompanyId name URLs); Data: Company- & gt; Is_mind (offer => 'data :: proposal' => 'company id'); # = & Gt; 'Company ID'

and

  Data :: Proposal-> Table ('Offer'); Data :: proposal-> Columns (all = & q; qw / OfferId CompanyId Monthly Price); Data :: offer-> Hisa (company = & gt; 'data :: company' = & gt; 'company id');  

I try to add a new record:

  My $ company = data :: company-> Insert ({name = & gt; 'test', url = & gt; 'http: // url'}); My $ offer = $ company- & gt; Add_to_offers ({monthly price = & gt; 100});  

But I'm getting:

  "add_to_offers" object method can not be detected by the package "data :: company"  

I saw classical music :: CD example, but I do not know what I'm doing.

I agree with you, if your package announcements are in the same file, then you Has_a () relationship is defined first. Otherwise, if they are in different source files, then the documentation says:

Class :: DBi should generally be able to do the right thing, as long as all classes are class: : Use any other class before DBI.

As a three-logic form, you're doing it right. The third ARB for has_many () is a foreign key column in this class. That is, offers has a CompanyId which indicates company 's CompanyId .


Comments