Welcome Guest, Not a member yet? Register   Sign In
IgnitedRecord 1.0 pre-release

[eluser]m4rw3r[/eluser]
At your first quesion: IR doesn't support multi-fk-relations natively, but by adding a WHERE (as you said) you can fix it:
Code:
$this->select('COUNT(comments.id) AS `comment_count`', false); // don't forget the false
$this->join_related('comments', true);
$this->where('area', 'blog');
Your second question: What are you trying to do? delete_all() deletes all records in the table, therefore the method is placed in the model. delete() is the method you call to delete a record.
(Cascades should preferably be configured in the database, but IR has the cascade_on_delete option for all has* relations (just set the key cascade_on_delete to true on one of the relation properties)).

[eluser]Jonas G[/eluser]
Thanks for the reply.

I must have misunderstood then - I though delete_all() would eg. delete my blog entry and all the related comments. But now I understand.

Cascades I have never heard of, but I will read up on that. Thanks again.

[eluser]JasonS[/eluser]
Hey, this may have been answered before but I have a question about generating forms.

I have 3 form fields.

Username, Email and Password.

I want, by default for the password field to be blank. (Currently it fills with the sha1 key Smile)

Then, if the password field is empty I do not want the field to be updated.

This is where I am little confused.

Where do I start on this? This is what I have.

Code:
public function edit($id)
    {
        $user = $this->user->find($id);
        
        if ( ! $user)
        {
            echo 'User not found';
            return;
        }
        
        if ($user->validate(array('username', 'email')))
        {
            $user->save();
        }
        
        echo $user->form();
        
        if ($_POST)
            $this->index(); // Buggy - Fix
    }

Code:
class User extends IgnitedRecord
{
    var $act_as = array (
        'validation' => array (
            'username' => array (
                'rules' => 'required|min_length[3]',
                'desc' => 'The username'
            ),
            'email' => array (
                'rules' => 'required|email',
                'desc' => 'The E-Mail'
            ),
            'password' => array (
                'rules' => 'required|min_length[6]',
                'desc' => 'The Password'
            )
        )    
    );
}

Basically. I have 3 questions.

How do I make the password field a password field?
How do I make the password field blank?
How do I check to see if the password field has been filled and update it? (I don't want to accidently update the password and wipe it.)

Thanks

[eluser]m4rw3r[/eluser]
For password field:
Code:
'password' = array(
    'rules' ...
    'type' => 'password'
    )
To make it blank and only update on change (this is a bit hacky, need to fix this in a future version of the form builder):
Code:
$user = $this->user->find($id) or whatever

// this sets the password to blank in the form without telling that it has changed
$user->password = $user->__data->password = '';

if($user->validate())
{
    // save, use $user->is_changed('password') to see if the password is changed
}

[eluser]JasonS[/eluser]
Thank you very much for your input and the speedy response. Its a great bit of kit and I really enjoy working with it. Just getting to grip with the finities Smile.

Could you tell me what the '__data' part does please?

Thanks.

[eluser]m4rw3r[/eluser]
The __data array contains a copy of the data stored in the object, and it is used to determine what has been changed.
(No need to update if it hasn't been changed)

[eluser]Jonas G[/eluser]
Hi again

I'm having trouble with the find_all() function. I want to end up with this query:
Code:
SELECT DISTINCT `event_id` FROM `goals`;

If I run:
Code:
$data['events'] = $this->goal->distinct()->select('event_id')->find_all();

I get:
Code:
SELECT DISTINCT `event_id`, `goals`.*
FROM `goals`;

I can't seem to find a way to not get the goals.* included unless i use get() instead of find_all(), but that limits the results to 1. What's the correct way of going about this problem?

[eluser]m4rw3r[/eluser]
Well, find_all() adds `table`.* to the select, to be certain that it receives the correct data.
In your case I would create the query with either ActiveRecord or IgnitedQuery:
Code:
// add this to your model or something:
function get_event_ids()
{
    $q = new IgnitedQuery();
    return $q->distinct()->select('event_id')->from('goals')->get();
}

[eluser]r2b2_kvr[/eluser]
hello,

i was just confused as to which version I'll use. 0.2 seems to be ok for me at the moment. Does 1.0 have the validation, form generation and the "through" relationship?

Thanks!

[eluser]r2b2_kvr[/eluser]
[quote author="m4rw3r" date="1240622817"]Well, find_all() adds `table`.* to the select, to be certain that it receives the correct data.
In your case I would create the query with either ActiveRecord or IgnitedQuery:
Code:
// add this to your model or something:
function get_event_ids()
{
    $q = new IgnitedQuery();
    return $q->distinct()->select('event_id')->from('goals')->get();
}
[/quote]

My solution to this is I edited IR and defined an attribute, (will post the code later)
which when set before calling find_all() will only select specified field

Code:
$this->model_name->fetch_all_columns = false;
$this->model_name->select('field')->find_all();

I believe this is before the select method is invoke in IR's find_* methods.




Theme © iAndrew 2016 - Forum software by © MyBB