CodeIgniter Forums
DMZ 1.7.1 (DataMapper OverZealous Edition) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DMZ 1.7.1 (DataMapper OverZealous Edition) (/showthread.php?tid=28550)



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-09-2010

[eluser]OverZealous[/eluser]
@All
Thanks for finding this bug and the fix. I'll make sure it gets into the next release of DMZ.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-10-2010

[eluser]Daniel H[/eluser]
[quote author="OverZealous" date="1281068626"]That being said, I'm pretty sure I've already determined out how to implement it with minimal impact to the library's performance.[/quote]

No problem - if you need me to test this feature out then let me know. :-)


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-10-2010

[eluser]Unknown[/eluser]
I think I've either found a bug or I'm not using it correctly.
Basically what I want to do is search upon a join field between a many-to-many relationship.

Here's the code needed to get a test working from a base CI and DMZ install.

MySQL Tables & Data
http://gist.github.com/518191

Attribute Model
http://gist.github.com/518199

Product Model
http://gist.github.com/518201

Controller
http://gist.github.com/518207

If you browse to the base url, or /welcome/index, you will get the following error:
Quote:A Database Error Occurred
Error Number: 1054

Unknown column 'attributes_products.value' in 'where clause'

SELECT * FROM (`products`) WHERE UPPER(`attributes_products`.`value`) LIKE '%SOMETHING%'

It's not adding the join for attributes_products.

What I ended up doing was editing libraries/datamapper.php and in _join_field() at line 5309 I added a line:
Code:
// Determine relationship table name, and join the tables
$rel_table = $this->_get_relationship_table($object, $related_field);
$this->_add_related_table($object, $related_field); // THIS WAS ADDED

I've tried everything from include_related() to include_join_fields() and nothing seems to get the right outcome except this hack above. I've not tested it anywhere else, so I don't know the impact this change will have elsewhere.

Am I doing it wrong or is this a bug?
Any help is appreciated!

EDIT: I noticed I used "or_ilike_join_field", since I copied it from a larger statement, but also "ilike_join_field" does not work


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-13-2010

[eluser]bonatoc[/eluser]
Hello,

Please, I need some help.

I have countries and currencies.
The relationship is : country has_one currency, with a currency_id column in countries

When editing a country, I want to assign a currency to the country. I use the htmlform extension (I know it's not supported anymore, but maybe some of you guys use it).
I pass this to render_form() :
Code:
$form_fields = array(
            'id',
            'CountryName',
            'currency'
        );

I have a 'currency' pull-out menu generated, and everything's fine.

Question : I have a 'Status' column in currencies, which is an ENUM set either to 'Active' or 'Inactive'.
At the moment, when creating the $country object, it retrieves all of the currencies.

How can I populate $country->currency with only currencies that are 'Active',
and then passing it to $country->render_form() ?

Can a subquery do the trick (the following does not work) ?
Code:
$country->include_related('currency')->where('Status','Active')->get_by_id($id);

or am I forced to create a currency object, and then pass it explicitely to the form, thus unexploiting the automatization process htmlform() provides ?

Thanks.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-13-2010

[eluser]bonatoc[/eluser]
I'm very interested in how you guys deal with ENUM switches on sub-objects.
Because obviously there can be many DB items which one would like to retrieve based on their 'ON','OFF' statuses.

Surely there must be a subquery technique which could avoid writing this :

Code:
// Get active currencies
        $currencies = new Currency;
        $currencies->where('Status', 'A')->get();

// Build an array to pass to the form field
        foreach ($currencies as $currencies_key)
        {
            $currency_id = $currencies_key->id;
            $currency_string = $currencies_key->CurrencyName;

            $currencies_array[$currency_id] = $currency_string;
        }
        reset($currencies);
        
        
        // These are the fields to edit.
        $form_fields = array(

            mb_ucfirst(str_Country) => 'section',
            'id',
            'CountryName',
            
            mb_ucfirst(str_Currency) => 'section',
            'currency' => array(
            'label' => str_ChooseCurrency,
            'list' => $currencies_array
            )

        );

I define some strings as constants, no errors in this code.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-14-2010

[eluser]kre8ivdesigns[/eluser]
Ok Need some help:

I have three table

reservations
id
checkin
checkout
numberofpeople
numberofdays

days_reservations
id
reservation_id
day_id

days
id
day


When someone comes to the site they will check availability. First I have the dates they chose to be matched to the days table to get the day_id

Now how do I check if the day_id exists in the join table days_reservation to return to the client that dates are taken or available.

The reason for the this setup is I have a rates table with a days_rates join

Thanks


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-14-2010

[eluser]OverZealous[/eluser]
[quote author="kre8ivdesigns" date="1281857684"]
Now how do I check if the day_id exists in the join table days_reservation to return to the client that dates are taken or available.[/quote]

Once you have the day, simply do:
Code:
if($day->reservation->count()) {
    // day taken
} else {
    // day not taken
}

This returns the number of reservations for a given day. As long as that can only be 0 or 1, this will work.

If you need to limit the reservations (ie: there can be more thab one reservation per day), simply add clauses into your statement:
Code:
$day->reservation->where(<<whatever>>)->count();



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-14-2010

[eluser]kre8ivdesigns[/eluser]
Fatal error: Class name must be a valid object or a string in D:\xampp\htdocs\test.com\application\libraries\datamapper.php on line 2418

And here are my models

Code:
&lt;?php

class Reservation extends DataMapper {    

    // Insert related models that Reservation can have just one of.
    var $has_one = array('client');
    
    // Insert related models that Reservation can have more than one of.
    var $has_many = array('days');
    
    // Validation
    //   Add validation requirements, such as 'required', for your fields.
    // --------------------------------------------------------------------


Code:
class Day extends DataMapper {
    
    // Uncomment and edit these two if the class has a model name that
    //   doesn't convert properly using the inflector_helper.
    // var $model = 'day';
    // var $table = 'days';
    
    // You can override the database connections with this option
    // var $db_params = 'db_config_name';
    
    // --------------------------------------------------------------------
    // Relationships
    //   Configure your relationships below
    // --------------------------------------------------------------------
    
    // Insert related models that Day can have just one of.
    var $has_one = array('rate');
    
    // Insert related models that Day can have more than one of.
    var $has_many = array('reservation');



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-14-2010

[eluser]kre8ivdesigns[/eluser]
Ok i tried that and it doesnt work... Thanks so far.

The goal

A client enters a checkin and checkout date

The dates they enter are populated into an date array to do a day by day check to the days table

If there is a match it returns the id from the days table

What I need to do is to see if the id from the days table is present in the days_reservations joined table and if it is that means the date is already booked.

Sorry for the trouble..

T


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 08-14-2010

[eluser]kre8ivdesigns[/eluser]
Here is the code

Code:
function check_dates($checkin,$checkout)
    {
        //convert times to right format
        $begindate = date('Y-m-d',(strtotime($checkin)));
        $enddate = date('Y-m-d',(strtotime($checkout)));
        
        //how many days are in between
        $date= round((strtotime($enddate) - strtotime($begindate)) / (60 * 60 * 24));
        
        //gather all the dates from the client and check database
        for ($i = 0; $i<$date; $i++) {
            $newdates = strtotime('+'.$i.' day', strtotime($begindate));
            $booking[$i] = date('Y-m-d', $newdates);
                
            //compare dates to database
            $d = new Day();
            $d->where('day',$booking[$i]);
            $d->get();
            $id = $d->id; // gives me the id from days table to use to compare to days_reservations tabe;
            
            //how to compare to days_reservations table
            
        }